Asset

Trait Asset 

pub trait Asset: Storable {
    const HOT_RELOADED: bool = true;

    // Required method
    fn load(
        cache: &AssetCache,
        id: &SharedString,
    ) -> Result<Self, Box<dyn Error + Sync + Send>>;
}
Expand description

An asset type that can load other kinds of assets.

Assets can be loaded and retrieved by an AssetCache.

Note that all FileAssets implement Asset.

Provided Associated Constants§

const HOT_RELOADED: bool = true

If false, disable hot-reloading for assets of this type (true by default). This avoids having to lock the asset to read it (ie it makes [Handle::read] a noop)

Required Methods§

fn load( cache: &AssetCache, id: &SharedString, ) -> Result<Self, Box<dyn Error + Sync + Send>>

Loads an asset from the cache.

The cache gives access to its underlying Source.

§Hot-reloading

Any file, directory or asset loaded from cache is registered as a dependency. When a dependency is modified (through direct modification or hot-reloading), the asset will be reloaded.

If you don’t use threads in this method, you don’t need to write hot-reloading-specific code.

An asset cannot depend on itself.

To opt out of dependencies recording, use AssetCache::no_record.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

§

impl<T> Asset for Arc<T>
where T: Asset,

§

const HOT_RELOADED: bool = T::HOT_RELOADED

§

fn load( cache: &AssetCache, id: &SharedString, ) -> Result<Arc<T>, Box<dyn Error + Sync + Send>>

Implementors§

Source§

impl<T> Asset for MultiRon<T>
where T: for<'de> Deserialize<'de> + Send + Sync + 'static + Concatenate,

§

impl<T> Asset for Directory<T>
where T: DirLoadable + Asset,

§

const HOT_RELOADED: bool = true

§

impl<T> Asset for RawDirectory<T>
where T: DirLoadable,

§

const HOT_RELOADED: bool = true

§

impl<T> Asset for RawRecursiveDirectory<T>
where T: DirLoadable,

§

const HOT_RELOADED: bool = true

§

impl<T> Asset for RecursiveDirectory<T>
where T: DirLoadable + Asset,

§

const HOT_RELOADED: bool = true

§

impl<T> Asset for T
where T: Compound,

§

const HOT_RELOADED: bool = <T as Compound>::HOT_RELOADED