pub struct LanguageTag<T: Borrow<str>>(/* private fields */);
Expand description
This wrapper guarantees that the underlying str
is a valid BCP47 language tag.
NB: it is actually more permissive than BCP47.
A LanguageTag
can be combined to a &str
with the *
operator,
to produce an RDF language tagged string
implementing the Term
trait:
let fr = LanguageTag::new_unchecked("fr");
let message = "Bonjour le monde" * fr;
assert!(message.is_literal());
assert_eq!(message.lexical_form().unwrap(), "Bonjour le monde");
assert_eq!(message.datatype().unwrap(), rdf::langString.iri().unwrap());
assert_eq!(message.language_tag().unwrap(), fr);
Implementations§
Source§impl<T: Borrow<str>> LanguageTag<T>
impl<T: Borrow<str>> LanguageTag<T>
Sourcepub fn new(tag: T) -> Result<Self, InvalidLanguageTag>
pub fn new(tag: T) -> Result<Self, InvalidLanguageTag>
Build a new LanguageTag
from tag
,
returning an error if it is not a valid BCP47 language tag.
Sourcepub fn new_unchecked(tag: T) -> Self
pub fn new_unchecked(tag: T) -> Self
Build a new LanguageTag
from tag
.
It does not check that the value returned by the function is valid.
If it is not, it may result in undefined behaviour.
Sourcepub fn as_ref(&self) -> LanguageTag<&str>
pub fn as_ref(&self) -> LanguageTag<&str>
Convert reference to a LanguageTag<&str>
Sourcepub fn map_unchecked<F, U>(self, f: F) -> LanguageTag<U>
pub fn map_unchecked<F, U>(self, f: F) -> LanguageTag<U>
Map a LanguageTag
<T>
to a LanguageTag
<U>
by applying a function to the wrapped value.
It does not check that the value returned by the function is valid. If it is not, it may result in undefined behaviour.
Source§impl LanguageTag<&'static str>
impl LanguageTag<&'static str>
Sourcepub const fn new_unchecked_const(inner: &'static str) -> Self
pub const fn new_unchecked_const(inner: &'static str) -> Self
Construct a LanguageTag<&'static>
without checking that the inner value is valid.
If it is not, it may result in undefined behaviour.
Trait Implementations§
Source§impl<T: Clone + Borrow<str>> Clone for LanguageTag<T>
impl<T: Clone + Borrow<str>> Clone for LanguageTag<T>
Source§fn clone(&self) -> LanguageTag<T>
fn clone(&self) -> LanguageTag<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<T: Borrow<str>> Mul<LanguageTag<T>> for Any
impl<T: Borrow<str>> Mul<LanguageTag<T>> for Any
Source§type Output = LanguageTagMatcher<T>
type Output = LanguageTagMatcher<T>
*
operator.