pub struct LiteralRef<'a>(/* private fields */);
Expand description
A borrowed RDF literal.
The default string formatter is returning an N-Triples, Turtle, and SPARQL compatible representation:
use oxrdf::vocab::xsd;
use oxrdf::LiteralRef;
assert_eq!(
"\"foo\\nbar\"",
LiteralRef::new_simple_literal("foo\nbar").to_string()
);
assert_eq!(
r#""1999-01-01"^^<http://www.w3.org/2001/XMLSchema#date>"#,
LiteralRef::new_typed_literal("1999-01-01", xsd::DATE).to_string()
);
Implementations§
Source§impl<'a> LiteralRef<'a>
impl<'a> LiteralRef<'a>
Sourcepub const fn new_simple_literal(value: &'a str) -> LiteralRef<'a>
pub const fn new_simple_literal(value: &'a str) -> LiteralRef<'a>
Builds an RDF simple literal.
Sourcepub fn new_typed_literal(
value: &'a str,
datatype: impl Into<NamedNodeRef<'a>>,
) -> LiteralRef<'a>
pub fn new_typed_literal( value: &'a str, datatype: impl Into<NamedNodeRef<'a>>, ) -> LiteralRef<'a>
Sourcepub const fn new_language_tagged_literal_unchecked(
value: &'a str,
language: &'a str,
) -> LiteralRef<'a>
pub const fn new_language_tagged_literal_unchecked( value: &'a str, language: &'a str, ) -> LiteralRef<'a>
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.
Sourcepub const fn value(self) -> &'a str
pub const fn value(self) -> &'a str
The literal lexical form
Sourcepub const fn language(self) -> Option<&'a str>
pub const fn language(self) -> Option<&'a 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.
Sourcepub const fn datatype(self) -> NamedNodeRef<'a>
pub const fn datatype(self) -> NamedNodeRef<'a>
The literal datatype.
The datatype of language-tagged string is always rdf:langString. The datatype of simple literals is xsd:string.
Sourcepub const fn is_plain(self) -> bool
pub const 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 into_owned(self) -> Literal
Trait Implementations§
Source§impl<'a> Clone for LiteralRef<'a>
impl<'a> Clone for LiteralRef<'a>
Source§fn clone(&self) -> LiteralRef<'a>
fn clone(&self) -> LiteralRef<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more