prefixmap/lib.rs
1//! Prefix map implementation
2//!
3//! Implements prefix maps, which are used in Turtle and ShEx
4//!
5//! A prefix map is a list of alias declarations associated with IRIs
6//!
7//! ```turtle
8//! prefix schema: <http://schema.org/>
9//! prefix : <http://example.org/>
10//! ```
11//!
12//! Example
13//!
14//! ```
15//! # use std::str::FromStr;
16//! # use iri_s::{IriS, IriSError};
17//! # use prefixmap::PrefixMap;
18//!
19//! # fn main() -> Result<(), IriSError> {
20//! let schema_iri = IriS::from_str("http://schema.org/")?;
21//! let example_iri = IriS::from_str("http://example.org/")?;
22//! let mut pm = PrefixMap::new();
23//! pm.insert("schema", &schema_iri);
24//! pm.insert("", &example_iri);
25//! # Ok(())
26//! # }
27//! ```
28
29// ```
30// let mut pm = PrefixMap::new();
31// let binding = ;
32// pm.insert("schema", &IriS::from_str("http://schema.org/"))
33// pm.insert("", &IriS::from_str("http://example.org/")?);
34// ```
35pub mod alias;
36pub mod deref;
37pub mod iri_ref;
38pub mod prefixmap;
39pub mod prefixmap_error;
40
41pub use crate::prefixmap::*;
42pub use alias::*;
43pub use deref::*;
44pub use iri_ref::*;
45pub use prefixmap_error::*;
46
47#[cfg(test)]
48mod tests {
49 use iri_s::IriS;
50 use std::str::FromStr;
51
52 use super::*;
53
54 #[test]
55 fn it_works() -> Result<(), PrefixMapError> {
56 let mut pm = PrefixMap::new();
57 let schema_iri = IriS::from_str("http://schema.org/")?;
58 pm.insert("schema", &schema_iri).unwrap();
59 let resolved = pm.resolve("schema:knows")?;
60 let schema_knows = IriS::from_str("http://schema.org/knows")?;
61 assert_eq!(resolved, schema_knows);
62 Ok(())
63 }
64}