AssetLoader

Trait AssetLoader 

Source
pub trait AssetLoader:
    Send
    + Sync
    + Debug
    + 'static {
    // Required methods
    fn load(&self, data: Vec<u8>, context: &mut LoaderContext<'_>);
    fn extension(&self) -> &[&str];
}
Expand description

A loader for an asset

Types implementing this trait are used by the AssetManager to load assets into their respective asset storages.

Required Methods§

Source

fn load(&self, data: Vec<u8>, context: &mut LoaderContext<'_>)

Process the asset creating an instance of the Asset from raw data

§Example
fn load(&self, data: Vec<u8>, context: &mut LoaderContext) {
    let img =
        image::load_from_memory(&data).unwrap_or_else(|e| panic!("Could not load image {}", e));

    let (width, height) = img.dimensions();

    let img = match img {
        DynamicImage::ImageRgba8(img) => img,
        img => img.to_rgba8(),
    };

    context.set_asset(Image {
        width,
        height,
        data: img.into_raw(),
    })
}
Source

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

Return a list of extensions supported by this asset loader. Without the dot

§Example
fn extension(&self) -> &[&str] {
   &["png", "jpg", "jpeg", "bmp"]
}

Implementors§