Trait Loader

Source
pub trait Loader {
    // Required method
    fn load(
        &self,
        specifier: &ModuleSpecifier,
        options: LoadOptions,
    ) -> LoadFuture;

    // Provided methods
    fn max_redirects(&self) -> usize { ... }
    fn cache_info_enabled(&self) -> bool { ... }
    fn get_cache_info(&self, _specifier: &ModuleSpecifier) -> Option<CacheInfo> { ... }
    fn ensure_cached(
        &self,
        specifier: &ModuleSpecifier,
        options: LoadOptions,
    ) -> EnsureCachedFuture { ... }
}
Expand description

A trait which allows asynchronous loading of source files into a module graph in a thread safe way as well as a way to provide additional meta data about any cached resources.

Required Methods§

Source

fn load(&self, specifier: &ModuleSpecifier, options: LoadOptions) -> LoadFuture

A method that given a specifier that asynchronously returns the source of the file.

To ensure errors surfaced in the graph are more specific for checksum integrity errors, ensure this returns a ChecksumIntegrityError when the checksum on LoadOptions does not match the loaded source.

Provided Methods§

Source

fn max_redirects(&self) -> usize

The maximum number of redirects allowed.

Source

fn cache_info_enabled(&self) -> bool

Whether getting cache info is enabled.

Source

fn get_cache_info(&self, _specifier: &ModuleSpecifier) -> Option<CacheInfo>

An optional method which returns cache info for a module specifier.

Source

fn ensure_cached( &self, specifier: &ModuleSpecifier, options: LoadOptions, ) -> EnsureCachedFuture

Ensures the specified module is cached.

By default, this will just call load, but you can override this to provide a more optimal way of caching that doesn’t load the bytes into memory.

Implementors§