oxigraph::model

Struct Literal

Source
pub struct Literal(/* private fields */);
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()
);

Implementations§

Source§

impl Literal

Source

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

Builds an RDF simple literal.

Source

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

Builds an RDF literal with a datatype.

Source

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

Builds an RDF language-tagged string.

Source

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.

Source

pub fn value(&self) -> &str

The literal lexical form.

Source

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.

Source

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.

Source

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.

Source

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

Source

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

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

Trait Implementations§

Source§

impl Clone for Literal

Source§

fn clone(&self) -> Literal

Returns a copy 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 Literal

Source§

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

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

impl Display for Literal

Source§

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

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

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl From<Boolean> for Literal

Source§

fn from(value: Boolean) -> Literal

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl From<Date> for Literal

Source§

fn from(value: Date) -> Literal

Converts to this type from the input type.
Source§

impl From<DateTime> for Literal

Source§

fn from(value: DateTime) -> Literal

Converts to this type from the input type.
Source§

impl From<DayTimeDuration> for Literal

Source§

fn from(value: DayTimeDuration) -> Literal

Converts to this type from the input type.
Source§

impl From<Decimal> for Literal

Source§

fn from(value: Decimal) -> Literal

Converts to this type from the input type.
Source§

impl From<Double> for Literal

Source§

fn from(value: Double) -> Literal

Converts to this type from the input type.
Source§

impl From<Duration> for Literal

Source§

fn from(value: Duration) -> Literal

Converts to this type from the input type.
Source§

impl From<Float> for Literal

Source§

fn from(value: Float) -> Literal

Converts to this type from the input type.
Source§

impl From<GDay> for Literal

Source§

fn from(value: GDay) -> Literal

Converts to this type from the input type.
Source§

impl From<GMonth> for Literal

Source§

fn from(value: GMonth) -> Literal

Converts to this type from the input type.
Source§

impl From<GMonthDay> for Literal

Source§

fn from(value: GMonthDay) -> Literal

Converts to this type from the input type.
Source§

impl From<GYear> for Literal

Source§

fn from(value: GYear) -> Literal

Converts to this type from the input type.
Source§

impl From<GYearMonth> for Literal

Source§

fn from(value: GYearMonth) -> Literal

Converts to this type from the input type.
Source§

impl From<Integer> for Literal

Source§

fn from(value: Integer) -> Literal

Converts to this type from the input type.
Source§

impl From<Literal> for Term

Source§

fn from(literal: Literal) -> Term

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl From<String> for Literal

Source§

fn from(value: String) -> Literal

Converts to this type from the input type.
Source§

impl From<Time> for Literal

Source§

fn from(value: Time) -> Literal

Converts to this type from the input type.
Source§

impl From<YearMonthDuration> for Literal

Source§

fn from(value: YearMonthDuration) -> Literal

Converts to this type from the input type.
Source§

impl From<bool> for Literal

Source§

fn from(value: bool) -> Literal

Converts to this type from the input type.
Source§

impl From<f32> for Literal

Source§

fn from(value: f32) -> Literal

Converts to this type from the input type.
Source§

impl From<f64> for Literal

Source§

fn from(value: f64) -> Literal

Converts to this type from the input type.
Source§

impl From<i128> for Literal

Source§

fn from(value: i128) -> Literal

Converts to this type from the input type.
Source§

impl From<i16> for Literal

Source§

fn from(value: i16) -> Literal

Converts to this type from the input type.
Source§

impl From<i32> for Literal

Source§

fn from(value: i32) -> Literal

Converts to this type from the input type.
Source§

impl From<i64> for Literal

Source§

fn from(value: i64) -> Literal

Converts to this type from the input type.
Source§

impl From<u16> for Literal

Source§

fn from(value: u16) -> Literal

Converts to this type from the input type.
Source§

impl From<u32> for Literal

Source§

fn from(value: u32) -> Literal

Converts to this type from the input type.
Source§

impl From<u64> for Literal

Source§

fn from(value: u64) -> Literal

Converts to this type from the input type.
Source§

impl FromStr for Literal

Source§

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

type Err = TermParseError

The associated error which can be returned from parsing.
Source§

impl Hash for Literal

Source§

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

impl PartialEq<Literal> for LiteralRef<'_>

Source§

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

impl PartialEq<LiteralRef<'_>> for Literal

Source§

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

impl PartialEq for Literal

Source§

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

impl TryFrom<Term> for Literal

Source§

type Error = TryFromTermError

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

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

Performs the conversion.
Source§

impl Eq for Literal

Source§

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
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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

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

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

Source§

fn vzip(self) -> V