pub trait Literal:
Debug
+ Clone
+ Display
+ PartialEq
+ Eq
+ Hash {
// Required methods
fn lexical_form(&self) -> &str;
fn lang(&self) -> Option<Lang>;
fn datatype(&self) -> IriRef;
fn to_concrete_literal(&self) -> Option<ConcreteLiteral>;
// Provided methods
fn to_bool(&self) -> Option<bool> { ... }
fn to_integer(&self) -> Option<isize> { ... }
fn to_date_time(&self) -> Option<XsdDateTime> { ... }
fn to_double(&self) -> Option<f64> { ... }
fn to_decimal(&self) -> Option<Decimal> { ... }
}Expand description
Types that implement this trait can be used as RDF Literals.
This trait provides methods for accessing literal properties and converting literals to specific Rust types based on their XSD datatype.
Required Methods§
Sourcefn lexical_form(&self) -> &str
fn lexical_form(&self) -> &str
Returns the lexical form of the literal as a string slice.
Sourcefn to_concrete_literal(&self) -> Option<ConcreteLiteral>
fn to_concrete_literal(&self) -> Option<ConcreteLiteral>
Converts this literal to an ConcreteLiteral if possible.
Provided Methods§
Sourcefn to_bool(&self) -> Option<bool>
fn to_bool(&self) -> Option<bool>
Attempts to convert this literal to a boolean value.
Returns Some(bool) if the literal has datatype xsd:boolean and
a valid lexical form (“true” or “false”).
Sourcefn to_integer(&self) -> Option<isize>
fn to_integer(&self) -> Option<isize>
Attempts to convert this literal to an integer value.
Returns Some(isize) if the literal has datatype xsd:integer and
a valid parseable lexical form.
Sourcefn to_date_time(&self) -> Option<XsdDateTime>
fn to_date_time(&self) -> Option<XsdDateTime>
Attempts to convert this literal to a datetime value.
Returns Some(XsdDateTime) if the literal has datatype xsd:dateTime and
a valid parseable lexical form.
Sourcefn to_double(&self) -> Option<f64>
fn to_double(&self) -> Option<f64>
Attempts to convert this literal to a double-precision float value.
Returns Some(f64) if the literal has datatype xsd:double and
a valid parseable lexical form.
Sourcefn to_decimal(&self) -> Option<Decimal>
fn to_decimal(&self) -> Option<Decimal>
Attempts to convert this literal to a decimal value.
Returns Some(Decimal) if the literal has datatype xsd:decimal and
a valid parseable lexical form.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl Literal for Literal
Implements the Literal trait for OxLiteral.
impl Literal for Literal
Implements the Literal trait for OxLiteral.
Provides access to literal values, language tags, and datatypes from
oxrdf literals.
Source§fn lexical_form(&self) -> &str
fn lexical_form(&self) -> &str
Returns the lexical form of the literal as a string slice.
Source§fn lang(&self) -> Option<Lang>
fn lang(&self) -> Option<Lang>
Returns the language tag if this is a language-tagged string.
§Returns
Some(Lang)if this literal has a language tag (e.g., “en”, “es”)Noneif this literal is not language-tagged
Source§fn to_concrete_literal(&self) -> Option<ConcreteLiteral>
fn to_concrete_literal(&self) -> Option<ConcreteLiteral>
Attempts to convert this literal to a concrete typed value.
§Returns
Some(ConcreteLiteral) if the literal can be parsed into a concrete type,
None otherwise.