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

source

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
source

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
source

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
source

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
source

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
source

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.

source

pub fn mappings(&self) -> Iter<'_, String, String>

Return an iterator over the prefix mappings.

The iterator yields IRI mappings in the same order they were inserted. This is useful when testing code that uses this crate.

Trait Implementations§

source§

impl Debug for PrefixMapping

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for PrefixMapping

source§

fn default() -> PrefixMapping

Returns the “default value” for a type. Read more
source§

impl PartialEq for PrefixMapping

source§

fn eq(&self, other: &PrefixMapping) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for PrefixMapping

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.