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

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 Reference by hand can be tedious, especially 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). The signature of get becomes:

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

Associated Types

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

Required methods

Convert the value into a reference.

Implementors