Skip to main content

NumericLiteral

Enum NumericLiteral 

Source
pub enum NumericLiteral {
Show 15 variants Integer(i128), Byte(i8), Short(i16), NonNegativeInteger(u128), UnsignedLong(u64), UnsignedInt(u32), UnsignedShort(u16), UnsignedByte(u8), PositiveInteger(u128), NegativeInteger(i128), NonPositiveInteger(i128), Long(i64), Decimal(Decimal), Double(f64), Float(f32),
}
Expand description

Represents RDF numeric literals with XSD datatype semantics.

This enum supports all XSD numeric types and provides type-safe conversions between them. Uses #[serde(untagged)] for flexible deserialization from JSON/other formats.

Variants§

§

Integer(i128)

§

Byte(i8)

§

Short(i16)

§

NonNegativeInteger(u128)

§

UnsignedLong(u64)

§

UnsignedInt(u32)

§

UnsignedShort(u16)

§

UnsignedByte(u8)

§

PositiveInteger(u128)

§

NegativeInteger(i128)

§

NonPositiveInteger(i128)

§

Long(i64)

§

Decimal(Decimal)

§

Double(f64)

§

Float(f32)

Implementations§

Source§

impl NumericLiteral

§Constructor Methods
Source

pub fn datatype(&self) -> &str

Returns the XSD datatype IRI for this numeric literal.

Each variant maps to its corresponding XML Schema datatype.

Source

pub fn decimal(d: Decimal) -> NumericLiteral

Creates a decimal literal from a Decimal value.

Source

pub fn non_positive_integer(n: i128) -> Result<NumericLiteral, RDFError>

Creates a non-positive integer literal from an i128 value.

§Errors

Returns error if value is greater than 0.

Source

pub fn non_negative_integer(n: u128) -> NumericLiteral

Creates a non-negative integer literal from a u128 value.

Source

pub fn positive_integer(n: u128) -> Result<NumericLiteral, RDFError>

Creates a positive integer literal (value > 0).

§Errors

Returns error if value is 0, as XSD positiveInteger requires > 0.

Source

pub fn negative_integer(n: i128) -> Result<NumericLiteral, RDFError>

Creates a negative integer literal from an i128 value.

§Errors

Returns error if value is greater than or equal to 0.

Source

pub fn unsigned_byte(n: u8) -> NumericLiteral

Creates an unsigned byte literal (0-255).

Source

pub fn unsigned_short(n: u16) -> NumericLiteral

Creates an unsigned short literal (0-65535).

Source

pub fn unsigned_int(n: u32) -> NumericLiteral

Creates an unsigned int literal.

Source

pub fn unsigned_long(n: u64) -> NumericLiteral

Creates an unsigned long literal.

Source

pub fn decimal_from_parts( whole: i64, fraction: u32, ) -> Result<NumericLiteral, RDFError>

Creates a decimal from separate whole and fractional parts.

§Errors

Returns error if the constructed string cannot be parsed as Decimal.

Source

pub fn byte(d: i8) -> NumericLiteral

Creates a byte literal (-128 to 127).

Source

pub fn short(d: i16) -> NumericLiteral

Creates a short literal (-32768 to 32767).

Source

pub fn long(d: i64) -> NumericLiteral

Creates a long literal (64-bit signed integer).

Source

pub fn float(d: f32) -> NumericLiteral

Creates a float literal (32-bit).

Source

pub fn integer(n: i128) -> NumericLiteral

Creates an integer literal (unbounded).

Source

pub fn double(d: f64) -> NumericLiteral

Creates a double literal (64-bit).

Source§

impl NumericLiteral

§Conversion Methods
Source

pub fn decimal_from_f64(d: f64) -> Result<NumericLiteral, RDFError>

Converts value to Decimal literal.

§Errors

Returns error if value cannot be represented as Decimal (e.g., NaN, infinity for floats).

Source

pub fn decimal_from_f32(d: f32) -> Result<NumericLiteral, RDFError>

Converts value to Decimal literal.

§Errors

Returns error if value cannot be represented as Decimal (e.g., NaN, infinity for floats).

Source

pub fn decimal_from_isize(d: isize) -> Result<NumericLiteral, RDFError>

Converts value to Decimal literal.

§Errors

Returns error if value cannot be represented as Decimal (e.g., NaN, infinity for floats).

Source

pub fn decimal_from_i32(d: i32) -> Result<NumericLiteral, RDFError>

Converts value to Decimal literal.

§Errors

Returns error if value cannot be represented as Decimal (e.g., NaN, infinity for floats).

Source

pub fn decimal_from_i64(d: i64) -> Result<NumericLiteral, RDFError>

Converts value to Decimal literal.

§Errors

Returns error if value cannot be represented as Decimal (e.g., NaN, infinity for floats).

Source

pub fn decimal_from_i128(d: i128) -> Result<NumericLiteral, RDFError>

Converts value to Decimal literal.

§Errors

Returns error if value cannot be represented as Decimal (e.g., NaN, infinity for floats).

Source

pub fn decimal_from_u32(d: u32) -> Result<NumericLiteral, RDFError>

Converts value to Decimal literal.

§Errors

Returns error if value cannot be represented as Decimal (e.g., NaN, infinity for floats).

Source

pub fn decimal_from_u64(d: u64) -> Result<NumericLiteral, RDFError>

Converts value to Decimal literal.

§Errors

Returns error if value cannot be represented as Decimal (e.g., NaN, infinity for floats).

Source

pub fn decimal_from_u128(d: u128) -> Result<NumericLiteral, RDFError>

Converts value to Decimal literal.

§Errors

Returns error if value cannot be represented as Decimal (e.g., NaN, infinity for floats).

Source

pub fn integer_from_i64(d: i64) -> NumericLiteral

Creates an integer literal from i64.

Source

pub fn integer_from_i128(d: i128) -> NumericLiteral

Creates an integer literal from i128.

Source

pub fn to_decimal(&self) -> Option<Decimal>

Converts any numeric literal to Decimal for uniform comparison.

This method enables cross-type numeric comparisons by normalizing all variants to the Decimal type.

Source§

impl NumericLiteral

§Utility Methods
Source

pub fn lexical_form(&self) -> String

Returns the lexical form (string representation) of this literal.

This is equivalent to the Display implementation.

Source

pub fn less_than(&self, other: &NumericLiteral) -> bool

Checks if this numeric literal is less than another.

Optimized for integer comparisons; falls back to decimal conversion for mixed-type comparisons.

Source

pub fn less_than_or_eq(&self, other: &NumericLiteral) -> bool

Checks if this numeric literal is less than or equal to another.

Source

pub fn total_digits(&self) -> Option<usize>

Returns the total number of digits in the literal.

For decimals, this excludes the decimal point and sign. Returns None for float/double as they don’t have a fixed digit count.

Source

pub fn fraction_digits(&self) -> Option<usize>

Returns the number of fractional digits.

Returns 0 for integer types, counts digits after decimal point for decimals, and None for float/double.

Trait Implementations§

Source§

impl Clone for NumericLiteral

Source§

fn clone(&self) -> NumericLiteral

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NumericLiteral

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for NumericLiteral

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for NumericLiteral

Display implementation for human-readable output.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<NumericLiteral> for Literal

Conversion to oxrdf::Literal for RDF serialization.

Source§

fn from(n: NumericLiteral) -> Self

Converts to this type from the input type.
Source§

impl Hash for NumericLiteral

Hash implementation consistent with the numeric-value-based equality above.

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for NumericLiteral

PartialEq that compares numeric value when possible (canonicalizing to Decimal).

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for NumericLiteral

Ordering based on decimal conversion for cross-type comparisons.

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for NumericLiteral

Custom serialization to preserve numeric types in target format.

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<&str> for NumericLiteral

Parse numeric literals from strings.

Attempts to parse as integer first, then float, then decimal.

Source§

type Error = String

The type returned in the event of a conversion error.
Source§

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for NumericLiteral

Eq implementation requires all values to be comparable.

Note: This implementation is consistent with Hash because both use the exact variant type + value, not normalized decimal values.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,