Literal

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::Literal;
use oxrdf::vocab::xsd;

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 new_directional_language_tagged_literal( value: impl Into<String>, language: impl Into<String>, direction: impl Into<BaseDirection>, ) -> Result<Literal, LanguageTagParseError>

Available on crate feature rdf-12 only.

pub fn new_directional_language_tagged_literal_unchecked( value: impl Into<String>, language: impl Into<String>, direction: impl Into<BaseDirection>, ) -> Literal

Available on crate feature rdf-12 only.

Builds an RDF directional 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 direction(&self) -> Option<BaseDirection>

Available on crate feature rdf-12 only.

The literal base direction if it is a directional language-tagged string.

The two possible base directions are left-to-right (ltr) and right-to-left (rtl).

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

👎Deprecated since 0.3.0: Plain literal concept is removed in RDF 1.1

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>, Option<BaseDirection>)

Available on crate feature rdf-12 only.

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

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

Available on crate feature oxsdatatypes only.
§

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

Available on crate feature oxsdatatypes only.
§

fn from(value: Date) -> Literal

Converts to this type from the input type.
§

impl From<DateTime> for Literal

Available on crate feature oxsdatatypes only.
§

fn from(value: DateTime) -> Literal

Converts to this type from the input type.
§

impl From<DayTimeDuration> for Literal

Available on crate feature oxsdatatypes only.
§

fn from(value: DayTimeDuration) -> Literal

Converts to this type from the input type.
§

impl From<Decimal> for Literal

Available on crate feature oxsdatatypes only.
§

fn from(value: Decimal) -> Literal

Converts to this type from the input type.
§

impl From<Double> for Literal

Available on crate feature oxsdatatypes only.
§

fn from(value: Double) -> Literal

Converts to this type from the input type.
§

impl From<Duration> for Literal

Available on crate feature oxsdatatypes only.
§

fn from(value: Duration) -> Literal

Converts to this type from the input type.
§

impl From<Float> for Literal

Available on crate feature oxsdatatypes only.
§

fn from(value: Float) -> Literal

Converts to this type from the input type.
§

impl From<GDay> for Literal

Available on crate feature oxsdatatypes only.
§

fn from(value: GDay) -> Literal

Converts to this type from the input type.
§

impl From<GMonth> for Literal

Available on crate feature oxsdatatypes only.
§

fn from(value: GMonth) -> Literal

Converts to this type from the input type.
§

impl From<GMonthDay> for Literal

Available on crate feature oxsdatatypes only.
§

fn from(value: GMonthDay) -> Literal

Converts to this type from the input type.
§

impl From<GYear> for Literal

Available on crate feature oxsdatatypes only.
§

fn from(value: GYear) -> Literal

Converts to this type from the input type.
§

impl From<GYearMonth> for Literal

Available on crate feature oxsdatatypes only.
§

fn from(value: GYearMonth) -> Literal

Converts to this type from the input type.
§

impl From<Integer> for Literal

Available on crate feature oxsdatatypes only.
§

fn from(value: Integer) -> Literal

Converts to this type from the input type.
§

impl From<Literal> for Expression

§

fn from(p: Literal) -> Expression

Converts to this type from the input type.
§

impl From<Literal> for Expression

§

fn from(value: Literal) -> Expression

Converts to this type from the input type.
§

impl From<Literal> for GroundTerm

§

fn from(literal: Literal) -> GroundTerm

Converts to this type from the input type.
§

impl From<Literal> for GroundTermPattern

§

fn from(literal: Literal) -> GroundTermPattern

Converts to this type from the input type.
§

impl From<Literal> for N3Term

§

fn from(literal: Literal) -> N3Term

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 From<Literal> for TermPattern

§

fn from(literal: Literal) -> TermPattern

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

Available on crate feature oxsdatatypes only.
§

fn from(value: Time) -> Literal

Converts to this type from the input type.
§

impl From<YearMonthDuration> for Literal

Available on crate feature oxsdatatypes only.
§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

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

Compare self to key and return true if they are equal.
§

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

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.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<E, T, Request, Encoding> FromReq<Patch<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
§

impl<E, T, Request, Encoding> FromReq<Post<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
§

impl<E, T, Request, Encoding> FromReq<Put<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
§

impl<E, Encoding, Response, T> FromRes<Patch<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
§

impl<E, Encoding, Response, T> FromRes<Post<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
§

impl<E, Encoding, Response, T> FromRes<Put<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
§

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<E, T, Encoding, Request> IntoReq<Patch<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
§

impl<E, T, Encoding, Request> IntoReq<Post<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
§

impl<E, T, Encoding, Request> IntoReq<Put<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
§

impl<E, Response, Encoding, T> IntoRes<Patch<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

§

async fn into_res(self) -> Result<Response, E>

Attempts to serialize the output into an HTTP response.
§

impl<E, Response, Encoding, T> IntoRes<Post<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

§

async fn into_res(self) -> Result<Response, E>

Attempts to serialize the output into an HTTP response.
§

impl<E, Response, Encoding, T> IntoRes<Put<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

§

async fn into_res(self) -> Result<Response, E>

Attempts to serialize the output into an HTTP response.
§

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> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> SerializableKey for T

§

fn ser_key(&self) -> String

Serializes the key to a unique string. Read more
§

impl<T> StorageAccess<T> for T

§

fn as_borrowed(&self) -> &T

Borrows the value.
§

fn into_taken(self) -> T

Takes the value.
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
§

impl<T> ToStringFallible for T
where T: Display,

§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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> Fruit for T
where T: Send + Downcast,