Struct Literal
pub struct Literal(LiteralContent);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: LiteralContentImplementations§
§impl Literal
impl Literal
pub fn new_simple_literal(value: impl Into<String>) -> Literal
pub fn new_simple_literal(value: impl Into<String>) -> Literal
Builds an RDF simple literal.
pub fn new_language_tagged_literal(
value: impl Into<String>,
language: impl Into<String>,
) -> Result<Literal, LanguageTagParseError>
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
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( value: impl Into<String>, language: impl Into<String>, direction: impl Into<BaseDirection>, ) -> Result<Literal, LanguageTagParseError>
rdf-12 only.Builds an RDF directional language-tagged string.
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.
pub fn new_directional_language_tagged_literal_unchecked( value: impl Into<String>, language: impl Into<String>, direction: impl Into<BaseDirection>, ) -> Literal
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
pub fn value(&self) -> &str
The literal lexical form.
pub fn language(&self) -> Option<&str>
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.
pub fn direction(&self) -> Option<BaseDirection>
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<'_>
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
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<'_>
Trait Implementations§
§impl From<Literal> for Expression
impl From<Literal> for Expression
§fn from(p: Literal) -> Expression
fn from(p: Literal) -> Expression
§impl From<Literal> for GroundTerm
impl From<Literal> for GroundTerm
§fn from(literal: Literal) -> GroundTerm
fn from(literal: Literal) -> GroundTerm
§impl From<Literal> for GroundTermPattern
impl From<Literal> for GroundTermPattern
§fn from(literal: Literal) -> GroundTermPattern
fn from(literal: Literal) -> GroundTermPattern
§impl From<Literal> for TermPattern
impl From<Literal> for TermPattern
§fn from(literal: Literal) -> TermPattern
fn from(literal: Literal) -> TermPattern
§impl FromStr for Literal
impl FromStr for Literal
§fn from_str(s: &str) -> Result<Literal, <Literal as FromStr>::Err>
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)
);impl Eq for Literal
impl StructuralPartialEq for Literal
Auto Trait Implementations§
impl Freeze for Literal
impl RefUnwindSafe for Literal
impl Send for Literal
impl Sync for Literal
impl Unpin for Literal
impl UnwindSafe for Literal
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<E, T, Request, Encoding> FromReq<Patch<Encoding>, Request, E> for Twhere
Request: Req<E> + Send + 'static,
Encoding: Decodes<T>,
E: FromServerFnError,
impl<E, T, Request, Encoding> FromReq<Patch<Encoding>, Request, E> for Twhere
Request: Req<E> + Send + 'static,
Encoding: Decodes<T>,
E: FromServerFnError,
§impl<E, T, Request, Encoding> FromReq<Post<Encoding>, Request, E> for Twhere
Request: Req<E> + Send + 'static,
Encoding: Decodes<T>,
E: FromServerFnError,
impl<E, T, Request, Encoding> FromReq<Post<Encoding>, Request, E> for Twhere
Request: Req<E> + Send + 'static,
Encoding: Decodes<T>,
E: FromServerFnError,
§impl<E, T, Request, Encoding> FromReq<Put<Encoding>, Request, E> for Twhere
Request: Req<E> + Send + 'static,
Encoding: Decodes<T>,
E: FromServerFnError,
impl<E, T, Request, Encoding> FromReq<Put<Encoding>, Request, E> for Twhere
Request: Req<E> + Send + 'static,
Encoding: Decodes<T>,
E: FromServerFnError,
§impl<E, Encoding, Response, T> FromRes<Patch<Encoding>, Response, E> for Twhere
Response: ClientRes<E> + Send,
Encoding: Decodes<T>,
E: FromServerFnError,
impl<E, Encoding, Response, T> FromRes<Patch<Encoding>, Response, E> for Twhere
Response: ClientRes<E> + Send,
Encoding: Decodes<T>,
E: FromServerFnError,
§impl<E, Encoding, Response, T> FromRes<Post<Encoding>, Response, E> for Twhere
Response: ClientRes<E> + Send,
Encoding: Decodes<T>,
E: FromServerFnError,
impl<E, Encoding, Response, T> FromRes<Post<Encoding>, Response, E> for Twhere
Response: ClientRes<E> + Send,
Encoding: Decodes<T>,
E: FromServerFnError,
§impl<E, Encoding, Response, T> FromRes<Put<Encoding>, Response, E> for Twhere
Response: ClientRes<E> + Send,
Encoding: Decodes<T>,
E: FromServerFnError,
impl<E, Encoding, Response, T> FromRes<Put<Encoding>, Response, E> for Twhere
Response: ClientRes<E> + Send,
Encoding: Decodes<T>,
E: FromServerFnError,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 Twhere
Request: ClientReq<E>,
Encoding: Encodes<T>,
E: FromServerFnError,
impl<E, T, Encoding, Request> IntoReq<Patch<Encoding>, Request, E> for Twhere
Request: ClientReq<E>,
Encoding: Encodes<T>,
E: FromServerFnError,
§impl<E, T, Encoding, Request> IntoReq<Post<Encoding>, Request, E> for Twhere
Request: ClientReq<E>,
Encoding: Encodes<T>,
E: FromServerFnError,
impl<E, T, Encoding, Request> IntoReq<Post<Encoding>, Request, E> for Twhere
Request: ClientReq<E>,
Encoding: Encodes<T>,
E: FromServerFnError,
§impl<E, T, Encoding, Request> IntoReq<Put<Encoding>, Request, E> for Twhere
Request: ClientReq<E>,
Encoding: Encodes<T>,
E: FromServerFnError,
impl<E, T, Encoding, Request> IntoReq<Put<Encoding>, Request, E> for Twhere
Request: ClientReq<E>,
Encoding: Encodes<T>,
E: FromServerFnError,
§impl<E, Response, Encoding, T> IntoRes<Patch<Encoding>, Response, E> for T
impl<E, Response, Encoding, T> IntoRes<Patch<Encoding>, Response, E> for T
§impl<E, Response, Encoding, T> IntoRes<Post<Encoding>, Response, E> for T
impl<E, Response, Encoding, T> IntoRes<Post<Encoding>, Response, E> for T
§impl<E, Response, Encoding, T> IntoRes<Put<Encoding>, Response, E> for T
impl<E, Response, Encoding, T> IntoRes<Put<Encoding>, Response, E> for T
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> SerializableKey for T
impl<T> SerializableKey for T
§impl<T> StorageAccess<T> for T
impl<T> StorageAccess<T> for T
§fn as_borrowed(&self) -> &T
fn as_borrowed(&self) -> &T
§fn into_taken(self) -> T
fn into_taken(self) -> T
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.