[][src]Trait json_ld::ToReference

pub trait ToReference<T: Id> {
    type Reference: Borrow<Reference<T>>;
    fn to_ref(&self) -> Self::Reference;
}

Types that can be converted into a borrowed node reference.

This is a convenient trait is used to simplify the use of references. For instance consider the Node::get method, used to get the objects associated to the given reference property for a given node. It essentially have the following signature:

fn get(&self, id: &Reference<T>) -> Objects;

However building a Refrence by hand can be tedious, especilly while using Lexicon and Vocab. It can be as verbose as node.get(&Reference::Id(Lexicon::Id(MyVocab::Term))). Thanks to ToReference which is implemented by Lexicon<V> for any type V implementing Vocab, it is simplified into node.get(MyVocab::Term) (while the first syntax remains correct) where the signature of get becomes:

fn get<R: ToReference<T>>(&self, id: R) -> Objects;

Associated Types

type Reference: Borrow<Reference<T>>

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

Loading content...

Required methods

fn to_ref(&self) -> Self::Reference

Convert the value into a reference.

Loading content...

Implementors

impl<'a, T: Id> ToReference<T> for &'a Reference<T>[src]

type Reference = &'a Reference<T>

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

type Reference = Reference<Lexicon<V>>

Loading content...