Skip to main content

AssetLoader

Trait AssetLoader 

Source
pub trait AssetLoader<A: Asset>:
    Send
    + Sync
    + 'static {
    // Required methods
    fn load(&self, bytes: &[u8], path: &AssetPath) -> Result<A, String>;
    fn extensions(&self) -> &[&str];
}
Expand description

Trait for loading raw bytes into a concrete Asset type.

Each asset format (PNG, WAV, GLSL, etc.) has one loader. Loaders are stateless by design; mutable state lives in AssetServer.

§Type parameter

A — the Asset type produced by this loader.

Required Methods§

Source

fn load(&self, bytes: &[u8], path: &AssetPath) -> Result<A, String>

Load an asset from the given byte slice.

path is provided for diagnostic messages; the loader must not perform additional I/O itself.

Returns Ok(asset) on success, Err(message) on failure.

Source

fn extensions(&self) -> &[&str]

Returns the file extensions this loader handles (without the dot).

Examples: &["png", "jpg"], &["glsl", "vert", "frag"].

Implementors§