Expand description
Lexicon identifier.
A Lexicon is a special identifier type (Id
) built from a Vocab
(vocabulary) type.
While Vocab
represents only a subset of all the possible IRIs, this type can also hold
any IRI outside of the predefined vocabulary.
It is a simple way to get an identifier type from a vocabulary.
Example
The following example builds a lexicon from a statically known vocabulary, defined as an
enum
type. It uses the iref-enum
crate to automatically derive the convertion of the
Vocab
type from/into IRIs.
use iref_enum::*;
use json_ld::Lexicon;
use serde_json::Value;
/// Vocabulary used in the implementation.
#[derive(IriEnum, Clone, Copy, PartialEq, Eq, Hash)]
#[iri_prefix("rdfs" = "http://www.w3.org/2000/01/rdf-schema#")]
#[iri_prefix("manifest" = "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#")]
#[iri_prefix("vocab" = "https://w3c.github.io/json-ld-api/tests/vocab#")]
pub enum Vocab {
#[iri("rdfs:comment")] Comment,
#[iri("manifest:name")] Name,
#[iri("manifest:entries")] Entries,
#[iri("manifest:action")] Action,
#[iri("manifest:result")] Result,
#[iri("vocab:PositiveEvaluationTest")] PositiveEvalTest,
#[iri("vocab:NegativeEvaluationTest")] NegativeEvalTest,
#[iri("vocab:option")] Option,
#[iri("vocab:specVersion")] SpecVersion,
#[iri("vocab:processingMode")] ProcessingMode,
#[iri("vocab:expandContext")] ExpandContext,
#[iri("vocab:base")] Base
}
/// A fully functional identifier type.
pub type Id = Lexicon<Vocab>;
fn handle_node(node: &json_ld::Node<Value, Id>) {
for name in node.get(Vocab::Name) { // <- note that we can directly use `Vocab` here.
println!("node name: {}", name.as_str().unwrap());
}
}
Variants
Id(V)
Identifier from the known vocabulary.
Iri(IriBuf)
Any other IRI outside of the vocabulary.
Trait Implementations
Auto Trait Implementations
impl<V> RefUnwindSafe for Lexicon<V> where
V: RefUnwindSafe,
impl<V> UnwindSafe for Lexicon<V> where
V: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more