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.
Asset
s can be loaded and retrieved by an AssetCache
.
Note that all FileAsset
s implement Asset
.
Provided Associated Constants§
const HOT_RELOADED: bool = true
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>>
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.