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§
Sourcefn load(&self, data: Vec<u8>, context: &mut LoaderContext<'_>)
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(),
})
}