pub struct NamespaceMapper { /* private fields */ }Expand description
Bidirectional registry of namespace prefixes and their IRIs.
Implementations§
Source§impl NamespaceMapper
impl NamespaceMapper
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a mapper pre-loaded with the most common RDF standard prefixes.
Sourcepub fn add(
&mut self,
prefix: impl Into<String>,
namespace: impl Into<String>,
) -> Result<(), NamespaceError>
pub fn add( &mut self, prefix: impl Into<String>, namespace: impl Into<String>, ) -> Result<(), NamespaceError>
Register a prefix mapping.
Returns Err(DuplicatePrefix) if the prefix is already registered.
Returns Err(InvalidPrefix) if the prefix string is empty or contains :
(only the bare name should be supplied; the trailing : is added automatically
during serialization).
Returns Err(InvalidNamespace) if the namespace is empty.
Sourcepub fn remove(&mut self, prefix: &str) -> bool
pub fn remove(&mut self, prefix: &str) -> bool
Remove a prefix mapping. Returns true if the mapping existed.
Sourcepub fn get_namespace(&self, prefix: &str) -> Option<&str>
pub fn get_namespace(&self, prefix: &str) -> Option<&str>
Look up the namespace for a given prefix.
Sourcepub fn get_prefix(&self, namespace: &str) -> Option<&str>
pub fn get_prefix(&self, namespace: &str) -> Option<&str>
Reverse-lookup: find a prefix for a given namespace IRI.
Sourcepub fn prefix_names(&self) -> Vec<&str>
pub fn prefix_names(&self) -> Vec<&str>
Return all registered prefix names.
Sourcepub fn all_mappings(&self) -> Vec<(&str, &str)>
pub fn all_mappings(&self) -> Vec<(&str, &str)>
Return all (prefix, namespace) pairs.
Sourcepub fn abbreviate(&self, iri: &str) -> Option<String>
pub fn abbreviate(&self, iri: &str) -> Option<String>
Try to abbreviate a full IRI to a CURIE (prefix:local).
Iterates all registered namespaces and returns the first match, choosing the longest matching namespace for determinism.
Sourcepub fn expand(&self, curie: &str) -> Option<String>
pub fn expand(&self, curie: &str) -> Option<String>
Expand a CURIE (prefix:local) to a full IRI.
Returns None if the prefix is not registered.
Sourcepub fn to_turtle_declarations(&self) -> String
pub fn to_turtle_declarations(&self) -> String
Produce Turtle @prefix declarations for all registered mappings.
Sourcepub fn to_sparql_declarations(&self) -> String
pub fn to_sparql_declarations(&self) -> String
Produce SPARQL PREFIX declarations for all registered mappings.
Sourcepub fn merge(&mut self, other: &NamespaceMapper)
pub fn merge(&mut self, other: &NamespaceMapper)
Merge all mappings from other into this mapper.
Silently skips any prefix that is already registered (no error).
Trait Implementations§
Source§impl Clone for NamespaceMapper
impl Clone for NamespaceMapper
Source§fn clone(&self) -> NamespaceMapper
fn clone(&self) -> NamespaceMapper
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NamespaceMapper
impl Debug for NamespaceMapper
Source§impl Default for NamespaceMapper
impl Default for NamespaceMapper
Source§fn default() -> NamespaceMapper
fn default() -> NamespaceMapper
Auto Trait Implementations§
impl Freeze for NamespaceMapper
impl RefUnwindSafe for NamespaceMapper
impl Send for NamespaceMapper
impl Sync for NamespaceMapper
impl Unpin for NamespaceMapper
impl UnsafeUnpin for NamespaceMapper
impl UnwindSafe for NamespaceMapper
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> 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