Skip to main content

AssetResolver

Trait AssetResolver 

Source
pub trait AssetResolver: Send + Sync {
    // Required method
    fn fetch(&self, uri: &str) -> Result<Vec<u8>, AssetError>;

    // Provided method
    fn resolve_id(&self, _id: &str) -> Option<String> { ... }
}

Required Methods§

Source

fn fetch(&self, uri: &str) -> Result<Vec<u8>, AssetError>

Fetch the bytes referenced by uri. The URI can be a relative or absolute path, an http:// / https:// URL, an asset-service reference, or anything else a caller-supplied resolver knows how to handle.

Provided Methods§

Source

fn resolve_id(&self, _id: &str) -> Option<String>

Resolve a bare asset id (no path, no extension — e.g. an asset service’s UUID) to a URI that fetch can load. A filesystem resolver searches its root recursively for a file whose stem matches; resolvers that can’t map an id return None (the default). Used as a fallback for {% media id="…" /%} when the id isn’t a file sitting directly in the asset root.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§