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::LiteralRef;
use oxrdf::vocab::xsd;
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) -> Self
pub const fn new_simple_literal(value: &'a str) -> Self
Builds an RDF simple literal.
Sourcepub fn new_typed_literal(
value: &'a str,
datatype: impl Into<NamedNodeRef<'a>>,
) -> Self
pub fn new_typed_literal( value: &'a str, datatype: impl Into<NamedNodeRef<'a>>, ) -> Self
Sourcepub const fn new_language_tagged_literal_unchecked(
value: &'a str,
language: &'a str,
) -> Self
pub const fn new_language_tagged_literal_unchecked( value: &'a str, language: &'a str, ) -> Self
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 new_directional_language_tagged_literal_unchecked(
value: &'a str,
language: &'a str,
direction: BaseDirection,
) -> Self
Available on crate feature rdf-12
only.
pub const fn new_directional_language_tagged_literal_unchecked( value: &'a str, language: &'a str, direction: BaseDirection, ) -> Self
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_directional_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 direction(self) -> Option<BaseDirection>
Available on crate feature rdf-12
only.
pub const 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
).
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
👎Deprecated since 0.3.0: Plain literal concept is removed in RDF 1.1
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 moreSource§impl<'a> Debug for LiteralRef<'a>
impl<'a> Debug for LiteralRef<'a>
Source§impl Display for LiteralRef<'_>
impl Display for LiteralRef<'_>
Source§impl<'a> From<&'a Literal> for LiteralRef<'a>
impl<'a> From<&'a Literal> for LiteralRef<'a>
Source§impl<'a> From<&'a str> for LiteralRef<'a>
impl<'a> From<&'a str> for LiteralRef<'a>
Source§impl From<LiteralRef<'_>> for Term
impl From<LiteralRef<'_>> for Term
Source§fn from(literal: LiteralRef<'_>) -> Self
fn from(literal: LiteralRef<'_>) -> Self
Source§impl<'a> From<LiteralRef<'a>> for Literal
impl<'a> From<LiteralRef<'a>> for Literal
Source§fn from(node: LiteralRef<'a>) -> Self
fn from(node: LiteralRef<'a>) -> Self
Source§impl<'a> From<LiteralRef<'a>> for TermRef<'a>
impl<'a> From<LiteralRef<'a>> for TermRef<'a>
Source§fn from(literal: LiteralRef<'a>) -> Self
fn from(literal: LiteralRef<'a>) -> Self
Source§impl<'a> Hash for LiteralRef<'a>
impl<'a> Hash for LiteralRef<'a>
Source§impl PartialEq<Literal> for LiteralRef<'_>
impl PartialEq<Literal> for LiteralRef<'_>
Source§impl PartialEq<LiteralRef<'_>> for Literal
impl PartialEq<LiteralRef<'_>> for Literal
Source§impl<'a> PartialEq for LiteralRef<'a>
impl<'a> PartialEq for LiteralRef<'a>
Source§impl Serialize for LiteralRef<'_>
Available on crate feature serde
only.
impl Serialize for LiteralRef<'_>
serde
only.