pub enum NumericLiteral {
}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
impl NumericLiteral
§Constructor Methods
Sourcepub fn datatype(&self) -> &str
pub fn datatype(&self) -> &str
Returns the XSD datatype IRI for this numeric literal.
Each variant maps to its corresponding XML Schema datatype.
Sourcepub fn decimal(d: Decimal) -> NumericLiteral
pub fn decimal(d: Decimal) -> NumericLiteral
Creates a decimal literal from a Decimal value.
Sourcepub fn non_positive_integer(n: i128) -> Result<NumericLiteral, RDFError>
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.
Sourcepub fn non_negative_integer(n: u128) -> NumericLiteral
pub fn non_negative_integer(n: u128) -> NumericLiteral
Creates a non-negative integer literal from a u128 value.
Sourcepub fn positive_integer(n: u128) -> Result<NumericLiteral, RDFError>
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.
Sourcepub fn negative_integer(n: i128) -> Result<NumericLiteral, RDFError>
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.
Sourcepub fn unsigned_byte(n: u8) -> NumericLiteral
pub fn unsigned_byte(n: u8) -> NumericLiteral
Creates an unsigned byte literal (0-255).
Sourcepub fn unsigned_short(n: u16) -> NumericLiteral
pub fn unsigned_short(n: u16) -> NumericLiteral
Creates an unsigned short literal (0-65535).
Sourcepub fn unsigned_int(n: u32) -> NumericLiteral
pub fn unsigned_int(n: u32) -> NumericLiteral
Creates an unsigned int literal.
Sourcepub fn unsigned_long(n: u64) -> NumericLiteral
pub fn unsigned_long(n: u64) -> NumericLiteral
Creates an unsigned long literal.
Sourcepub fn decimal_from_parts(
whole: i64,
fraction: u32,
) -> Result<NumericLiteral, RDFError>
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.
Sourcepub fn byte(d: i8) -> NumericLiteral
pub fn byte(d: i8) -> NumericLiteral
Creates a byte literal (-128 to 127).
Sourcepub fn short(d: i16) -> NumericLiteral
pub fn short(d: i16) -> NumericLiteral
Creates a short literal (-32768 to 32767).
Sourcepub fn long(d: i64) -> NumericLiteral
pub fn long(d: i64) -> NumericLiteral
Creates a long literal (64-bit signed integer).
Sourcepub fn float(d: f32) -> NumericLiteral
pub fn float(d: f32) -> NumericLiteral
Creates a float literal (32-bit).
Sourcepub fn integer(n: i128) -> NumericLiteral
pub fn integer(n: i128) -> NumericLiteral
Creates an integer literal (unbounded).
Sourcepub fn double(d: f64) -> NumericLiteral
pub fn double(d: f64) -> NumericLiteral
Creates a double literal (64-bit).
Source§impl NumericLiteral
§Conversion Methods
impl NumericLiteral
§Conversion Methods
Sourcepub fn decimal_from_f64(d: f64) -> Result<NumericLiteral, RDFError>
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).
Sourcepub fn decimal_from_f32(d: f32) -> Result<NumericLiteral, RDFError>
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).
Sourcepub fn decimal_from_isize(d: isize) -> Result<NumericLiteral, RDFError>
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).
Sourcepub fn decimal_from_i32(d: i32) -> Result<NumericLiteral, RDFError>
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).
Sourcepub fn decimal_from_i64(d: i64) -> Result<NumericLiteral, RDFError>
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).
Sourcepub fn decimal_from_i128(d: i128) -> Result<NumericLiteral, RDFError>
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).
Sourcepub fn decimal_from_u32(d: u32) -> Result<NumericLiteral, RDFError>
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).
Sourcepub fn decimal_from_u64(d: u64) -> Result<NumericLiteral, RDFError>
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).
Sourcepub fn decimal_from_u128(d: u128) -> Result<NumericLiteral, RDFError>
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).
Sourcepub fn integer_from_i64(d: i64) -> NumericLiteral
pub fn integer_from_i64(d: i64) -> NumericLiteral
Creates an integer literal from i64.
Sourcepub fn integer_from_i128(d: i128) -> NumericLiteral
pub fn integer_from_i128(d: i128) -> NumericLiteral
Creates an integer literal from i128.
Sourcepub fn to_decimal(&self) -> Option<Decimal>
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
impl NumericLiteral
§Utility Methods
Sourcepub fn lexical_form(&self) -> String
pub fn lexical_form(&self) -> String
Returns the lexical form (string representation) of this literal.
This is equivalent to the Display implementation.
Sourcepub fn less_than(&self, other: &NumericLiteral) -> bool
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.
Sourcepub fn less_than_or_eq(&self, other: &NumericLiteral) -> bool
pub fn less_than_or_eq(&self, other: &NumericLiteral) -> bool
Checks if this numeric literal is less than or equal to another.
Sourcepub fn total_digits(&self) -> Option<usize>
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.
Sourcepub fn fraction_digits(&self) -> Option<usize>
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
impl Clone for NumericLiteral
Source§fn clone(&self) -> NumericLiteral
fn clone(&self) -> NumericLiteral
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NumericLiteral
impl Debug for NumericLiteral
Source§impl<'de> Deserialize<'de> for NumericLiteral
impl<'de> Deserialize<'de> for NumericLiteral
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for NumericLiteral
Display implementation for human-readable output.
impl Display for NumericLiteral
Display implementation for human-readable output.
Source§impl From<NumericLiteral> for Literal
Conversion to oxrdf::Literal for RDF serialization.
impl From<NumericLiteral> for Literal
Conversion to oxrdf::Literal for RDF serialization.
Source§fn from(n: NumericLiteral) -> Self
fn from(n: NumericLiteral) -> Self
Source§impl Hash for NumericLiteral
Hash implementation consistent with the numeric-value-based equality above.
impl Hash for NumericLiteral
Hash implementation consistent with the numeric-value-based equality above.
Source§impl PartialEq for NumericLiteral
PartialEq that compares numeric value when possible (canonicalizing to Decimal).
impl PartialEq for NumericLiteral
PartialEq that compares numeric value when possible (canonicalizing to Decimal).
Source§impl PartialOrd for NumericLiteral
Ordering based on decimal conversion for cross-type comparisons.
impl PartialOrd for NumericLiteral
Ordering based on decimal conversion for cross-type comparisons.
Source§impl Serialize for NumericLiteral
Custom serialization to preserve numeric types in target format.
impl Serialize for NumericLiteral
Custom serialization to preserve numeric types in target format.
Source§impl TryFrom<&str> for NumericLiteral
Parse numeric literals from strings.
impl TryFrom<&str> for NumericLiteral
Parse numeric literals from strings.
Attempts to parse as integer first, then float, then decimal.
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§
impl Freeze for NumericLiteral
impl RefUnwindSafe for NumericLiteral
impl Send for NumericLiteral
impl Sync for NumericLiteral
impl Unpin for NumericLiteral
impl UnsafeUnpin for NumericLiteral
impl UnwindSafe for NumericLiteral
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.