Skip to main content

Literal

Trait Literal 

Source
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§

Source

fn lexical_form(&self) -> &str

Returns the lexical form of the literal as a string slice.

Source

fn lang(&self) -> Option<Lang>

Returns the language tag if this is a language-tagged literal.

Source

fn datatype(&self) -> IriRef

Returns the datatype IRI of this literal.

Source

fn to_concrete_literal(&self) -> Option<ConcreteLiteral>

Converts this literal to an ConcreteLiteral if possible.

Provided Methods§

Source

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”).

Source

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.

Source

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.

Source

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.

Source

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.

Provides access to literal values, language tags, and datatypes from oxrdf literals.

Source§

fn lexical_form(&self) -> &str

Returns the lexical form of the literal as a string slice.

Source§

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”)
  • None if this literal is not language-tagged
Source§

fn datatype(&self) -> IriRef

Returns the datatype IRI of this literal.

Source§

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.

Implementors§