Skip to main content

ResourceLoader

Trait ResourceLoader 

Source
pub trait ResourceLoader: Send + Sync {
    type Resource: Send + Sync;
    type Error: Error + Send + Sync + 'static + From<Error> + From<Error>;

    // Required methods
    fn load_from_bytes(
        &self,
        bytes: Vec<u8>,
    ) -> Result<Self::Resource, Self::Error>;
    fn label(&self) -> &'static str;

    // Provided methods
    fn load_from_path(&self, path: &str) -> Result<Self::Resource, Self::Error> { ... }
    fn load_all(
        &self,
        root: &str,
    ) -> Result<HashMap<Identifier, Self::Resource>, Self::Error> { ... }
}
Expand description

Abstraction of a resource loader

Required Associated Types§

Source

type Resource: Send + Sync

Source

type Error: Error + Send + Sync + 'static + From<Error> + From<Error>

Required Methods§

Source

fn load_from_bytes(&self, bytes: Vec<u8>) -> Result<Self::Resource, Self::Error>

load a file from the bytes

Source

fn label(&self) -> &'static str

Name of the resource loader

Provided Methods§

Source

fn load_from_path(&self, path: &str) -> Result<Self::Resource, Self::Error>

Implemented by default, load a file from path

Source

fn load_all( &self, root: &str, ) -> Result<HashMap<Identifier, Self::Resource>, Self::Error>

Load a file system into a hashmap

Implementors§