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
type Asset: Asset
The asset type this context can produce.
type Data
The Data
type the asset can be created from.
type Error: Error + Send + Sync
The error that may be returned from create_asset
.
type Result: IntoFuture<Item = Self::Asset, Error = Self::Error>
The result type for loading an asset. This can also be a future
(or anything that implements IntoFuture
).
Required Methods
fn category(&self) -> &str
A small keyword for which category these assets belongs to.
Examples
"mesh"
forMesh
"data"
forLevel
The storage may use this information, to e.g. search the identically-named subfolder.
fn create_asset(&self, data: Self::Data, pool: &ThreadPool) -> Self::Result
Provides the conversion from the data format to the actual asset.
fn update(&self, spec: &AssetSpec, asset: AssetFuture<Self::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
fn cache(&self, _spec: AssetSpec, _asset: AssetFuture<Self::Asset>)
Notifies about an asset load. This is can be used to cache the asset.
To return a cached asset, see the retrieve
function.
fn retrieve(&self, _spec: &AssetSpec) -> Option<AssetFuture<Self::Asset>>
Returns Some
cached value if possible, otherwise None
.
For a basic implementation of a cache, please take a look at the Cache
type.
fn clear(&self)
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.
fn clear_all(&self)
Request for clearing the whole cache.
Implementors
impl<A, D, E, R, T> Context for SimpleContext<A, D, T> where
A: Clone,
R: Send + 'static,
D: Send + 'static,
T: Fn(D) -> R + Send + Sync + 'static,
SimpleAsset<A>: Asset + Clone + Send + 'static,
E: Error + Send + Sync,
R: IntoFuture<Item = SimpleAsset<A>, Error = E>,