[][src]Struct sophia_term::literal::Literal

pub struct Literal<TD: TermData> { /* fields omitted */ }

An RDF literal.

Each literals has a lexical value, i.e. a text, and a datatype.

Language tagged literals

Language-tagged literals have the type rdf:langString and an additional language-tag.

The tags conform to BCP47.

Datatypes

Datatypes in RDF have a lexical scope and a value scope. Transformation between them is done by the lexical-to-value mapping of a datatype. If the text of a typed literal is not in the value space of its datatype, literal is called ill-typed or malformed. However, RDF specification explicitly requires implementations to accept those literals. In the end such malformed literals lead to logical inconsistency in a graph.

Implementations

impl<TD> Literal<TD> where
    TD: TermData
[src]

pub fn new_lang<U, V>(txt: U, tag: V) -> Result<Self> where
    V: AsRef<str>,
    TD: From<U> + From<V>, 
[src]

Return a new language-tagged literal.

Error

If tag is not a valid language-tag according to BCP47 an error is raised.

pub fn new_dt<U, V>(txt: U, dt: Iri<V>) -> Self where
    TD: From<U> + From<V>,
    V: TermData
[src]

Return a new literal with an arbitrary datatype.

Neither is checked if dt refers to a known datatype nor if txt is ill-type and not in the lexical space of dt. This is intended as the RDF specification requires implementations to accept ill-typed literals.

pub fn new_lang_unchecked<U, V>(txt: U, tag: V) -> Self where
    V: AsRef<str>,
    TD: From<U> + From<V>, 
[src]

Return a new language-tagged literal.

Pre-condition

tag must be a valid language-tag according to BCP47. In debug mode this is asserted.

pub fn as_ref(&self) -> Literal<&TD>[src]

Borrow the inner contents of the literal.

pub fn as_ref_str(&self) -> Literal<&str>[src]

Borrow the inner contents of the literal as &str.

pub fn map<F, TD2>(self, f: F) -> Literal<TD2> where
    F: FnMut(TD) -> TD2,
    TD2: TermData
[src]

Create a new literal by applying f to the TermData of self.

pub fn map_into<TD2>(self) -> Literal<TD2> where
    TD: Into<TD2>,
    TD2: TermData
[src]

Maps the literal using the Into trait.

pub fn clone_map<'a, U, F>(&'a self, factory: F) -> Literal<U> where
    U: TermData,
    F: FnMut(&'a str) -> U, 
[src]

Clone self while transforming the inner TermData with the given factory.

This is done in one step in contrast to calling clone().map(factory).

pub fn clone_into<'src, U>(&'src self) -> Literal<U> where
    U: TermData + From<&'src str>, 
[src]

Apply clone_map() using the Into trait.

pub fn normalized(&self, policy: Normalization) -> Literal<MownStr<'_>>[src]

Return a literal equivalent to this one, with its datatype (if any) is internally represented with all its data in ns, and an empty suffix.

Performances

The returned literal will borrow data from this one as much as possible, but strings may be allocated in case a concatenation is required.

pub fn write_fmt<W>(&self, w: &mut W) -> Result where
    W: Write
[src]

Writes the literal to the fmt::Write using the NTriples syntax.

pub fn write_io<W>(&self, w: &mut W) -> Result<()> where
    W: Write
[src]

Writes the literal to the io::Write using the NTriples syntax.

pub fn txt(&self) -> &TD[src]

Returns the literal's lexical value.

pub fn dt(&self) -> Iri<&str>[src]

Return an IRI borrowing the literals datatype.

Note: A language-tagged literal has always the type rdf:langString.

pub fn lang(&self) -> Option<&TD>[src]

Return the language-tag of the literal if it has one.

pub fn eq_txt<U>(&self, other: Literal<U>) -> bool where
    U: TermData
[src]

Check if both literals have the same lexical value.

Trait Implementations

impl<TD: Clone + TermData> Clone for Literal<TD>[src]

impl<TD: Copy + TermData> Copy for Literal<TD>[src]

impl<TD: Debug + TermData> Debug for Literal<TD>[src]

impl<TD> Display for Literal<TD> where
    TD: TermData
[src]

impl<T: TermData> Eq for Literal<T>[src]

impl<TD> From<Literal<TD>> for Term<TD> where
    TD: TermData
[src]

impl<'a, T: ?Sized> From<NativeLiteral<T, &'a str>> for Literal<&'a str> where
    T: DataType
[src]

impl<T: ?Sized, TD> From<NativeLiteral<T, Box<str>>> for Literal<TD> where
    T: DataType,
    TD: TermData + From<Box<str>> + From<&'static str>, 
[src]

impl<TD> Hash for Literal<TD> where
    TD: TermData
[src]

impl<TD: TermData> Ord for Literal<TD>[src]

impl<TD, TE: ?Sized> PartialEq<TE> for Literal<TD> where
    TD: TermData,
    TE: TTerm
[src]

impl<TD, TE: ?Sized> PartialOrd<TE> for Literal<TD> where
    TD: TermData,
    TE: TTerm
[src]

impl<'a, 'b, TD> Resolve<&'a Literal<TD>, Literal<MownStr<'a>>> for IriParsed<'b> where
    TD: TermData
[src]

fn resolve(&self, other: &'a Literal<TD>) -> Literal<MownStr<'a>>[src]

Resolve the data type's IRI if it is relative.

Note that this only affects datatyped literals; language-tagged literals are absolute by construction.

Performance

May allocate an intermediate IRI if other.dt() is suffixed.

impl<TD: TermData> TTerm for Literal<TD>[src]

impl<TD> TryCopyTerm for Literal<TD> where
    TD: TermData + for<'x> From<&'x str>, 
[src]

type Error = TermError

The error type produced when failing to copy a given term

impl<'a, T, U> TryFrom<&'a Term<U>> for Literal<T> where
    T: TermData + From<&'a str>,
    U: TermData
[src]

type Error = TermError

The type returned in the event of a conversion error.

impl<TD> TryFrom<Term<TD>> for Literal<TD> where
    TD: TermData
[src]

type Error = TermError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<TD> RefUnwindSafe for Literal<TD> where
    TD: RefUnwindSafe

impl<TD> Send for Literal<TD> where
    TD: Send

impl<TD> Sync for Literal<TD> where
    TD: Sync

impl<TD> Unpin for Literal<TD> where
    TD: Unpin

impl<TD> UnwindSafe for Literal<TD> where
    TD: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> ConvertibleTerm for T where
    T: TTerm + ?Sized
[src]

impl<T> CopiableTerm for T where
    T: TTerm + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<U> TermMatcher for U where
    U: TTerm + ?Sized
[src]

type Term = U

Type of TTerm used internally by this matcher.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.