Crate curie [] [src]

CURIEs: Compact URIs

CURIEs, defined by the W3C, are a compact way of representing a URI. A CURIE consists of an optional prefix and a reference, separated by a colon.

Example CURIEs:

  • "foaf:Person" -- Results in a URI in the foaf namespace.
  • ":Person" -- Results in a URI in the default namespace.
  • "Person" -- Results in a URI in the default namespace.

The last two examples rely upon there being a default mapping providing a default base URI.

See the specification for further details.

Usage

use curie::PrefixMapping;

// Initialize a prefix mapper.
let mut mapper = PrefixMapping::default();
mapper.add_prefix("foaf", "http://xmlns.com/foaf/0.1/").unwrap();

// Set a default prefix
mapper.set_default("http://example.com/");

// Expand a CURIE and get back the full URI.
assert_eq!(mapper.expand("Entity"),
           Ok(String::from("http://example.com/Entity")));
assert_eq!(mapper.expand("foaf:Agent"),
           Ok(String::from("http://xmlns.com/foaf/0.1/Agent")));

Structs

PrefixMapping

Maps prefixes to base URIs and allows for the expansion of CURIEs (Compact URIs).

Enums

ExpansionError

Errors that might occur during CURIE expansion.

InvalidPrefixError

Errors that might occur when adding a prefix to a PrefixMapping.