Trait amethyst_assets::Context [] [src]

pub trait Context: Send + Sync + 'static {
    type Asset: Asset;
    type Data;
    type Error: Error + Send + Sync;
    type Result: IntoFuture<Item = Self::Asset, Error = Self::Error>;
    fn category(&self) -> &str;
fn create_asset(&self, data: Self::Data, pool: &ThreadPool) -> Self::Result;
fn update(&self, spec: &AssetSpec, asset: AssetFuture<Self::Asset>); fn cache(&self, _spec: AssetSpec, _asset: AssetFuture<Self::Asset>) { ... }
fn retrieve(&self, _spec: &AssetSpec) -> Option<AssetFuture<Self::Asset>> { ... }
fn clear(&self) { ... }
fn clear_all(&self) { ... } }

The context type which manages assets of one type. It is responsible for caching

Associated Types

The asset type this context can produce.

The Data type the asset can be created from.

The error that may be returned from create_asset.

The result type for loading an asset. This can also be a future (or anything that implements IntoFuture).

Required Methods

A small keyword for which category these assets belongs to.

Examples

  • "mesh" for Mesh
  • "data" for Level

The storage may use this information, to e.g. search the identically-named subfolder.

Provides the conversion from the data format to the actual asset.

Updates an asset after it's been reloaded.

This usually just puts the new asset into a queue; the actual update happens by calling update on the asset.

Provided Methods

Notifies about an asset load. This is can be used to cache the asset. To return a cached asset, see the retrieve function.

Returns Some cached value if possible, otherwise None.

For a basic implementation of a cache, please take a look at the Cache type.

Gives a hint that several assets may have been released recently.

This is useful if your assets are reference counted, because you are now able to remove unique assets from the cache, leaving the shared ones there.

Request for clearing the whole cache.

Implementors