Skip to main content

Loader

Trait Loader 

Source
pub trait Loader {
    type Error: Error + Send + Sync + 'static;

    // Required method
    async fn load(
        &self,
        url: Iri<&str>,
    ) -> Result<RemoteDocument<IriBuf>, LoadError<Self::Error>>;

    // Provided method
    async fn load_with<V>(
        &self,
        vocabulary: &mut V,
        url: V::Iri,
    ) -> LoadingResult<V::Iri, Self::Error>
       where V: IriVocabularyMut,
             V::Iri: Clone + Eq + Hash { ... }
}
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 + Send + Sync + 'static

Loader-specific error type.

Required Methods§

Source

async fn load( &self, url: Iri<&str>, ) -> Result<RemoteDocument<IriBuf>, LoadError<Self::Error>>

Loads the document behind the given IRI.

Provided Methods§

Source

async fn load_with<V>( &self, vocabulary: &mut V, url: V::Iri, ) -> LoadingResult<V::Iri, Self::Error>
where V: IriVocabularyMut, V::Iri: Clone + Eq + Hash,

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

§Panics

Panics if url does not resolve in vocabulary, i.e. if it was obtained from a different vocabulary.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Loader for BTreeMap<IriBuf, RemoteDocument>

Source§

impl<L: Loader> Loader for &L

Source§

type Error = <L as Loader>::Error

Source§

async fn load_with<V>( &self, vocabulary: &mut V, url: V::Iri, ) -> LoadingResult<V::Iri, Self::Error>
where V: IriVocabularyMut, V::Iri: Clone + Eq + Hash,

Source§

async fn load( &self, url: Iri<&str>, ) -> Result<RemoteDocument<IriBuf>, LoadError<Self::Error>>

Source§

impl<L: Loader> Loader for &mut L

Source§

type Error = <L as Loader>::Error

Source§

async fn load_with<V>( &self, vocabulary: &mut V, url: V::Iri, ) -> LoadingResult<V::Iri, Self::Error>
where V: IriVocabularyMut, V::Iri: Clone + Eq + Hash,

Source§

async fn load( &self, url: Iri<&str>, ) -> Result<RemoteDocument<IriBuf>, LoadError<Self::Error>>

Source§

impl<S: BuildHasher + Send + Sync> Loader for HashMap<IriBuf, RemoteDocument, S>

Implementors§

Source§

impl Loader for FsLoader

Source§

impl Loader for NoLoader

Source§

impl Loader for ReqwestLoader

Available on crate feature reqwest only.
Source§

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

Source§

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