Struct Literal

pub struct Literal(LiteralContent);
Available on crate feature rdf only.
Expand description

An owned RDF literal.

The default string formatter is returning an N-Triples, Turtle, and SPARQL compatible representation:

use oxrdf::vocab::xsd;
use oxrdf::Literal;

assert_eq!(
    "\"foo\\nbar\"",
    Literal::new_simple_literal("foo\nbar").to_string()
);

assert_eq!(
    r#""1999-01-01"^^<http://www.w3.org/2001/XMLSchema#date>"#,
    Literal::new_typed_literal("1999-01-01", xsd::DATE).to_string()
);

assert_eq!(
    r#""foo"@en"#,
    Literal::new_language_tagged_literal("foo", "en")?.to_string()
);

Tuple Fieldsยง

ยง0: LiteralContent

Implementationsยง

ยง

impl Literal

pub fn new_simple_literal(value: impl Into<String>) -> Literal

Builds an RDF simple literal.

pub fn new_typed_literal( value: impl Into<String>, datatype: impl Into<NamedNode>, ) -> Literal

Builds an RDF literal with a datatype.

pub fn new_language_tagged_literal( value: impl Into<String>, language: impl Into<String>, ) -> Result<Literal, LanguageTagParseError>

Builds an RDF language-tagged string.

pub fn new_language_tagged_literal_unchecked( value: impl Into<String>, language: impl Into<String>, ) -> Literal

Builds an RDF language-tagged string.

It is the responsibility of the caller to check that language is valid BCP47 language tag, and is lowercase.

Literal::new_language_tagged_literal() is a safe version of this constructor and should be used for untrusted data.

pub fn value(&self) -> &str

The literal lexical form.

pub fn language(&self) -> Option<&str>

The literal language tag if it is a language-tagged string.

Language tags are defined by the BCP47. They are normalized to lowercase by this implementation.

pub fn datatype(&self) -> NamedNodeRef<'_>

The literal datatype.

The datatype of language-tagged string is always rdf:langString. The datatype of simple literals is xsd:string.

pub fn is_plain(&self) -> bool

Checks if this literal could be seen as an RDF 1.0 plain literal.

It returns true if the literal is a language-tagged string or has the datatype xsd:string.

pub fn as_ref(&self) -> LiteralRef<'_>

pub fn destruct(self) -> (String, Option<NamedNode>, Option<String>)

Extract components from this literal (value, datatype and language tag).

Trait Implementationsยง

ยง

impl Clone for Literal

ยง

fn clone(&self) -> Literal

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
ยง

impl Debug for Literal

ยง

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

Formats the value using the given formatter. Read more
ยง

impl Display for Literal

ยง

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

Formats the value using the given formatter. Read more
ยง

impl<'a> From<&'a Literal> for LiteralRef<'a>

ยง

fn from(node: &'a Literal) -> LiteralRef<'a>

Converts to this type from the input type.
ยง

impl<'a> From<&'a Literal> for TermRef<'a>

ยง

fn from(literal: &'a Literal) -> TermRef<'a>

Converts to this type from the input type.
ยง

impl<'a> From<&'a str> for Literal

ยง

fn from(value: &'a str) -> Literal

Converts to this type from the input type.
ยง

impl From<Boolean> for Literal

ยง

fn from(value: Boolean) -> Literal

Converts to this type from the input type.
ยง

impl<'a> From<Cow<'a, str>> for Literal

ยง

fn from(value: Cow<'a, str>) -> Literal

Converts to this type from the input type.
ยง

impl From<Date> for Literal

ยง

fn from(value: Date) -> Literal

Converts to this type from the input type.
ยง

impl From<DateTime> for Literal

ยง

fn from(value: DateTime) -> Literal

Converts to this type from the input type.
ยง

impl From<DayTimeDuration> for Literal

ยง

fn from(value: DayTimeDuration) -> Literal

Converts to this type from the input type.
ยง

impl From<Decimal> for Literal

ยง

fn from(value: Decimal) -> Literal

Converts to this type from the input type.
ยง

impl From<Double> for Literal

ยง

fn from(value: Double) -> Literal

Converts to this type from the input type.
ยง

impl From<Duration> for Literal

ยง

fn from(value: Duration) -> Literal

Converts to this type from the input type.
ยง

impl From<Float> for Literal

ยง

fn from(value: Float) -> Literal

Converts to this type from the input type.
ยง

impl From<GDay> for Literal

ยง

fn from(value: GDay) -> Literal

Converts to this type from the input type.
ยง

impl From<GMonth> for Literal

ยง

fn from(value: GMonth) -> Literal

Converts to this type from the input type.
ยง

impl From<GMonthDay> for Literal

ยง

fn from(value: GMonthDay) -> Literal

Converts to this type from the input type.
ยง

impl From<GYear> for Literal

ยง

fn from(value: GYear) -> Literal

Converts to this type from the input type.
ยง

impl From<GYearMonth> for Literal

ยง

fn from(value: GYearMonth) -> Literal

Converts to this type from the input type.
ยง

impl From<Integer> for Literal

ยง

fn from(value: Integer) -> Literal

Converts to this type from the input type.
ยง

impl From<Literal> for Term

ยง

fn from(literal: Literal) -> Term

Converts to this type from the input type.
ยง

impl<'a> From<LiteralRef<'a>> for Literal

ยง

fn from(node: LiteralRef<'a>) -> Literal

Converts to this type from the input type.
ยง

impl From<String> for Literal

ยง

fn from(value: String) -> Literal

Converts to this type from the input type.
ยง

impl From<Time> for Literal

ยง

fn from(value: Time) -> Literal

Converts to this type from the input type.
ยง

impl From<YearMonthDuration> for Literal

ยง

fn from(value: YearMonthDuration) -> Literal

Converts to this type from the input type.
ยง

impl From<bool> for Literal

ยง

fn from(value: bool) -> Literal

Converts to this type from the input type.
ยง

impl From<f32> for Literal

ยง

fn from(value: f32) -> Literal

Converts to this type from the input type.
ยง

impl From<f64> for Literal

ยง

fn from(value: f64) -> Literal

Converts to this type from the input type.
ยง

impl From<i128> for Literal

ยง

fn from(value: i128) -> Literal

Converts to this type from the input type.
ยง

impl From<i16> for Literal

ยง

fn from(value: i16) -> Literal

Converts to this type from the input type.
ยง

impl From<i32> for Literal

ยง

fn from(value: i32) -> Literal

Converts to this type from the input type.
ยง

impl From<i64> for Literal

ยง

fn from(value: i64) -> Literal

Converts to this type from the input type.
ยง

impl From<u16> for Literal

ยง

fn from(value: u16) -> Literal

Converts to this type from the input type.
ยง

impl From<u32> for Literal

ยง

fn from(value: u32) -> Literal

Converts to this type from the input type.
ยง

impl From<u64> for Literal

ยง

fn from(value: u64) -> Literal

Converts to this type from the input type.
ยง

impl FromStr for Literal

ยง

fn from_str(s: &str) -> Result<Literal, <Literal as FromStr>::Err>

Parses a literal from its NTriples serialization

use oxrdf::vocab::xsd;
use oxrdf::{Literal, NamedNode};
use std::str::FromStr;

assert_eq!(
    Literal::from_str("\"ex\\n\"")?,
    Literal::new_simple_literal("ex\n")
);
assert_eq!(
    Literal::from_str("\"ex\"@en")?,
    Literal::new_language_tagged_literal("ex", "en")?
);
assert_eq!(
    Literal::from_str("\"2020\"^^<http://www.w3.org/2001/XMLSchema#gYear>")?,
    Literal::new_typed_literal(
        "2020",
        NamedNode::new("http://www.w3.org/2001/XMLSchema#gYear")?
    )
);
assert_eq!(
    Literal::from_str("true")?,
    Literal::new_typed_literal("true", xsd::BOOLEAN)
);
assert_eq!(
    Literal::from_str("+122")?,
    Literal::new_typed_literal("+122", xsd::INTEGER)
);
assert_eq!(
    Literal::from_str("-122.23")?,
    Literal::new_typed_literal("-122.23", xsd::DECIMAL)
);
assert_eq!(
    Literal::from_str("-122e+1")?,
    Literal::new_typed_literal("-122e+1", xsd::DOUBLE)
);
ยง

type Err = TermParseError

The associated error which can be returned from parsing.
ยง

impl Hash for Literal

ยง

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

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
ยง

impl PartialEq<Literal> for LiteralRef<'_>

ยง

fn eq(&self, other: &Literal) -> 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.
ยง

impl PartialEq<LiteralRef<'_>> for Literal

ยง

fn eq(&self, other: &LiteralRef<'_>) -> 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.
ยง

impl PartialEq for Literal

ยง

fn eq(&self, other: &Literal) -> 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.
ยง

impl TryFrom<Term> for Literal

ยง

type Error = TryFromTermError

The type returned in the event of a conversion error.
ยง

fn try_from(term: Term) -> Result<Literal, <Literal as TryFrom<Term>>::Error>

Performs the conversion.
ยง

impl Eq for Literal

ยง

impl StructuralPartialEq for Literal

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
ยง

impl<T> ArchivePointee for T

ยง

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
ยง

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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
ยง

impl<T> CallHasher for T
where T: Hash + ?Sized,

ยง

default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64
where H: Hash + ?Sized, B: BuildHasher,

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
ยง

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

ยง

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
ยง

impl<T> Downcast for T
where T: Any,

ยง

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
ยง

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
ยง

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Anyโ€™s vtable from &Traitโ€™s.
ยง

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Anyโ€™s vtable from &mut Traitโ€™s.
ยง

impl<T> DowncastSend for T
where T: Any + Send,

ยง

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
ยง

impl<T> DowncastSync for T
where T: Any + Send + Sync,

ยง

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
ยง

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
ยง

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

ยง

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

Checks if this value is equivalent to the given key. Read more
ยง

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

ยง

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.

ยง

impl<T> Instrument for T

ยง

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

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
ยง

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> IntoEither for T

Sourceยง

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Sourceยง

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
ยง

impl<T> Pointable for T

ยง

const ALIGN: usize

The alignment of pointer.
ยง

type Init = T

The type for initializers.
ยง

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
ยง

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
ยง

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
ยง

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
ยง

impl<T> Pointee for T

ยง

type Metadata = ()

The type for metadata in pointers and references to 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, 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.
ยง

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

ยง

fn vzip(self) -> V

ยง

impl<T> WithSubscriber for T

ยง

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
ยง

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
ยง

impl<T> ErasedDestructor for T
where T: 'static,

ยง

impl<T> Fruit for T
where T: Send + Downcast,