Trait json_ld::Loader

source ·
pub trait Loader<I = IriBuf> {
    type Error;

    // Required method
    async fn load_with<V>(
        &mut self,
        vocabulary: &mut V,
        url: I
    ) -> Result<RemoteDocument<I>, Self::Error>
       where V: IriVocabularyMut<Iri = I>;

    // Provided method
    async fn load(&mut self, url: I) -> Result<RemoteDocument<I>, Self::Error>
       where (): IriVocabulary<Iri = I> { ... }
}
Expand description

Document loader.

A document loader is required by most processing functions to fetch remote documents identified by an IRI. In particular, the loader is in charge of fetching all the remote contexts imported in a @context entry.

This library provides a few default loader implementations:

  • NoLoader dummy loader that always fail. Perfect if you are certain that the processing will not require any loading.
  • Standard HashMap and BTreeMap mapping IRIs to pre-loaded documents. This way no network calls are performed and the loaded content can be trusted.
  • FsLoader that redirecting registered IRI prefixes to a local directory on the file system. This also avoids network calls. The loaded content can be trusted as long as the file system is trusted.
  • ReqwestLoader actually downloading the remote documents using the reqwest library. This requires the reqwest feature to be enabled.

Required Associated Types§

source

type Error

Error type.

Required Methods§

source

async fn load_with<V>( &mut self, vocabulary: &mut V, url: I ) -> Result<RemoteDocument<I>, Self::Error>
where V: IriVocabularyMut<Iri = I>,

Loads the document behind the given IRI, using the given vocabulary.

Provided Methods§

source

async fn load(&mut self, url: I) -> Result<RemoteDocument<I>, Self::Error>
where (): IriVocabulary<Iri = I>,

Loads the document behind the given IRI.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'l, I, L> Loader<I> for &'l mut L
where L: Loader<I>,

§

type Error = <L as Loader<I>>::Error

source§

async fn load_with<V>( &mut self, vocabulary: &mut V, url: I ) -> Result<RemoteDocument<I>, <&'l mut L as Loader<I>>::Error>
where V: IriVocabularyMut<Iri = I>,

source§

async fn load( &mut self, url: I ) -> Result<RemoteDocument<I>, <&'l mut L as Loader<I>>::Error>
where (): IriVocabulary<Iri = I>,

source§

impl<I> Loader<I> for BTreeMap<I, RemoteDocument<I>>
where I: Clone + Ord,

§

type Error = EntryNotFound<I>

source§

async fn load_with<V>( &mut self, _vocabulary: &mut V, url: I ) -> Result<RemoteDocument<I>, <BTreeMap<I, RemoteDocument<I>> as Loader<I>>::Error>
where V: IriVocabulary<Iri = I>,

source§

impl<I> Loader<I> for HashMap<I, RemoteDocument<I>>
where I: Clone + Eq + Hash,

§

type Error = EntryNotFound<I>

source§

async fn load_with<V>( &mut self, _vocabulary: &mut V, url: I ) -> Result<RemoteDocument<I>, <HashMap<I, RemoteDocument<I>> as Loader<I>>::Error>
where V: IriVocabulary<Iri = I>,

Implementors§

source§

impl<I> Loader<I> for FsLoader<I>

§

type Error = Error

source§

impl<I> Loader<I> for NoLoader

source§

impl<I> Loader<I> for ReqwestLoader<I>
where I: Clone + Eq + Hash,

§

type Error = Error

source§

impl<I, L1, L2> Loader<I> for ChainLoader<L1, L2>
where I: Clone, L1: Loader<I>, L2: Loader<I>,

§

type Error = Error<<L1 as Loader<I>>::Error, <L2 as Loader<I>>::Error>