LoadableResource

Trait LoadableResource 

Source
pub trait LoadableResource: Any {
    // Required methods
    fn load(
        path: PathBuf,
        graphics: &mut Graphics,
        size: Option<f32>,
    ) -> Result<Box<dyn LoadableResource>>
       where Self: Sized;
    fn name(&self) -> String;

    // Provided methods
    fn as_mut_slice(&self) -> Option<&mut [u8]> { ... }
    fn as_slice(&self) -> Option<Ref<'_, [u8]>> { ... }
}
Expand description

Trait that all loadable assets must implement

Required Methods§

Source

fn load( path: PathBuf, graphics: &mut Graphics, size: Option<f32>, ) -> Result<Box<dyn LoadableResource>>
where Self: Sized,

Load a resource from path and return it boxed

§Arguments

path: path to the resoruce file graphics: current Graphics instance which holds texture_creator and ttf_context size: optional size for any resoruce that needs it

§Errors

Returns an error if the file cannot be read or parsed

Source

fn name(&self) -> String

Eaasy-to-use identifier for the resource

Provided Methods§

Source

fn as_mut_slice(&self) -> Option<&mut [u8]>

Return a mutable slice that the graphics thread can pass to SDL

If the resource does not have a buffer, then it mustn’t implement this function

Source

fn as_slice(&self) -> Option<Ref<'_, [u8]>>

Return an immutable slice for read‑only access

If the resource does not have a buffer, then it mustn’t implement this function

Implementors§