[][src]Enum json_ld::Lexicon

pub enum Lexicon<V: Vocab> {
    Id(V),
    Iri(IriBuf),
}

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.

#[macro_use]
extern crate iref_enum;
extern crate json_ld;

use json_ld::Lexicon;

/// 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<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

impl<V: Clone + Vocab> Clone for Lexicon<V>[src]

impl<V: Vocab> Display for Lexicon<V>[src]

impl<V: Eq + Vocab> Eq for Lexicon<V>[src]

impl<V: Hash + Vocab> Hash for Lexicon<V>[src]

impl<V: Vocab> Id for Lexicon<V>[src]

impl<V: PartialEq + Vocab> PartialEq<Lexicon<V>> for Lexicon<V>[src]

impl<V: Vocab> PartialEq<V> for Lexicon<V>[src]

impl<V: Vocab> StructuralEq for Lexicon<V>[src]

impl<V: Vocab> StructuralPartialEq for Lexicon<V>[src]

impl<V: Vocab> ToReference<Lexicon<V>> for V[src]

type Reference = Reference<Lexicon<V>>

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

Auto Trait Implementations

impl<V> RefUnwindSafe for Lexicon<V> where
    V: RefUnwindSafe

impl<V> Send for Lexicon<V> where
    V: Send

impl<V> Sync for Lexicon<V> where
    V: Sync

impl<V> Unpin for Lexicon<V> where
    V: Unpin

impl<V> UnwindSafe for Lexicon<V> where
    V: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToOwned for T[src]

type Owned = T

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.