pub enum Lexicon<V: Vocab> {
    Id(V),
    Iri(IriBuf),
}
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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

Create an identifier from its IRI.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The target type of the conversion, which can be borrowed as a Reference<T>.

Convert the value into a reference.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.