pub struct Assets<A: Asset> { /* private fields */ }Expand description
A central, in-memory cache for a specific type of asset A.
This structure maps a unique AssetUUID to a shared AssetHandle<A>.
This ensures that any given asset is loaded only once. Subsequent requests
for the same asset will receive a clone of the cached handle.
Implementations§
Source§impl<A: Asset> Assets<A>
impl<A: Asset> Assets<A>
Sourcepub fn insert(&mut self, uuid: AssetUUID, handle: AssetHandle<A>)
pub fn insert(&mut self, uuid: AssetUUID, handle: AssetHandle<A>)
Inserts an asset handle into the storage, associated with its UUID. If an asset with the same UUID already exists, it will be replaced. This operation is always successful.
§Arguments
uuid- The unique identifier for the asset.handle- The handle to the asset to be stored.
Sourcepub fn get(&self, uuid: &AssetUUID) -> Option<&AssetHandle<A>>
pub fn get(&self, uuid: &AssetUUID) -> Option<&AssetHandle<A>>
Retrieves a reference to the asset handle associated with the given UUID.
Returns None if no asset with the specified UUID is found.
Sourcepub fn contains(&self, uuid: &AssetUUID) -> bool
pub fn contains(&self, uuid: &AssetUUID) -> bool
Checks if an asset with the specified UUID exists in the storage.
Sourcepub fn remove(&mut self, uuid: &AssetUUID) -> Option<AssetHandle<A>>
pub fn remove(&mut self, uuid: &AssetUUID) -> Option<AssetHandle<A>>
Drops the cached handle for uuid, returning it if present.
Used by AssetService::invalidate (in khora-io) when a hot-reload
event invalidates a cached asset. Note that any outstanding clones of
the returned handle keep the old asset alive until they themselves
drop — that’s by design: in-flight readers don’t see a half-loaded
replacement. The next AssetService::load for the same UUID re-runs
the IO + decoder pipeline and produces a fresh handle.