Trait veloren_common_assets::Compound

pub trait Compound: Sized + Send + Sync + 'static {
    const HOT_RELOADED: bool = true;

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

An asset type that can load other kinds of assets.

Compounds can be loaded and retrieved by an AssetCache.

A Compound often needs to reference other assets, but Compound requires 'static and a Handle is borrowed. See top-level documentation for workarounds.

Note that all Assets implement Compound.

§Hot-reloading

Any asset loaded from the given cache is registered as a dependency of the Compound. When the former is reloaded, the latter will be reloaded too. An asset cannot depend on itself, or it may cause deadlocks to happen.

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

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: AnyCache<'_>, id: &SharedString, ) -> Result<Self, Box<dyn Error + Send + Sync>>

Loads an asset from the cache.

This function should not perform any kind of I/O: such concern should be delegated to Assets.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

§

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

§

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

§

const HOT_RELOADED: bool = T::HOT_RELOADED

Implementors§

source§

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

§

impl<T> Compound for Directory<T>
where T: DirLoadable,

§

const HOT_RELOADED: bool = true

§

impl<T> Compound for RecursiveDirectory<T>
where T: DirLoadable,

§

const HOT_RELOADED: bool = true

§

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

§

const HOT_RELOADED: bool = Self::HOT_RELOADED