Struct curie::PrefixMapping
source · pub struct PrefixMapping { /* private fields */ }
Expand description
Maps prefixes to base URIs and allows for the expansion of CURIEs (Compact URIs).
Examples
use curie::PrefixMapping;
// Create using the `Default` trait:
let mut mapping = PrefixMapping::default();
Implementations§
source§impl PrefixMapping
impl PrefixMapping
sourcepub fn set_default(&mut self, default: &str)
pub fn set_default(&mut self, default: &str)
Set a default prefix.
This is used during CURIE expansion when there is no prefix, just a reference value.
Example:
use curie::{ExpansionError, PrefixMapping};
let mut mapping = PrefixMapping::default();
// No default has been configured, so an error will be
// signaled.
assert_eq!(mapping.expand_curie_string("Entity"),
Err(ExpansionError::MissingDefault));
mapping.set_default("http://example.com/");
assert_eq!(mapping.expand_curie_string("Entity"),
Ok(String::from("http://example.com/Entity")));
See also
sourcepub fn add_prefix(
&mut self,
prefix: &str,
value: &str
) -> Result<(), InvalidPrefixError>
pub fn add_prefix( &mut self, prefix: &str, value: &str ) -> Result<(), InvalidPrefixError>
Add a prefix to the mapping.
This allows this prefix to be resolved when a CURIE is expanded.
Errors
Returns InvalidPrefixError
when the prefix
is invalid. Typically, this is
when prefix
is _
, which is a reserved prefix.
See also
sourcepub fn remove_prefix(&mut self, prefix: &str)
pub fn remove_prefix(&mut self, prefix: &str)
Remove a prefix from the mapping.
Future calls to PrefixMapping::expand_curie_string()
or PrefixMapping::expand_curie()
that use this prefix
will result in a ExpansionError::Invalid
error.
See also
sourcepub fn expand_curie_string(
&self,
curie_str: &str
) -> Result<String, ExpansionError>
pub fn expand_curie_string( &self, curie_str: &str ) -> Result<String, ExpansionError>
Expand a CURIE, returning a complete IRI.
Errors
This will return ExpansionError
if the expansion fails.
See also
sourcepub fn expand_curie(&self, curie: &Curie<'_>) -> Result<String, ExpansionError>
pub fn expand_curie(&self, curie: &Curie<'_>) -> Result<String, ExpansionError>
Expand a parsed Curie
, returning a complete IRI.
Errors
This will return ExpansionError
if the expansion fails.
See also
sourcepub fn shrink_iri<'a>(&'a self, iri: &'a str) -> Result<Curie<'a>, &'static str>
pub fn shrink_iri<'a>(&'a self, iri: &'a str) -> Result<Curie<'a>, &'static str>
Shrink an IRI, returning a Curie
.
If several base IRIs match the expanded IRI passed as argument, the one that was inserted first is used, even though another base IRI is a better match:
use curie::{PrefixMapping, Curie};
let mut mapping = PrefixMapping::default();
mapping.add_prefix("eg", "http://example.com/").unwrap();
mapping.add_prefix("egdoc", "http://example.com/document/").unwrap();
assert_eq!(mapping.shrink_iri("http://example.com/document/thing"),
Ok(Curie::new(Some("eg"), "document/thing")));
Errors
An error is returned if there is no valid mapping (default or otherwise) that would allow the IRI to be shortened.
Trait Implementations§
source§impl Debug for PrefixMapping
impl Debug for PrefixMapping
source§impl Default for PrefixMapping
impl Default for PrefixMapping
source§fn default() -> PrefixMapping
fn default() -> PrefixMapping
source§impl PartialEq for PrefixMapping
impl PartialEq for PrefixMapping
source§fn eq(&self, other: &PrefixMapping) -> bool
fn eq(&self, other: &PrefixMapping) -> bool
self
and other
values to be equal, and is used
by ==
.