pub struct Assets<T: 'static + Send + Sync> { /* private fields */ }Expand description
Storage for raw CPU-side assets of type T.
Assets are inserted by name and looked up by either name or
RawAssetHandle. When an asset is inserted or updated its handle is
pushed onto the dirty queue, which the sync system drains each tick to
upload changed assets to the GPU.
Implementations§
Source§impl<T: 'static + Send + Sync> Assets<T>
impl<T: 'static + Send + Sync> Assets<T>
pub fn new() -> Self
Sourcepub fn insert(&mut self, name: &str, asset: T) -> RawAssetHandle
pub fn insert(&mut self, name: &str, asset: T) -> RawAssetHandle
Insert asset under name, returning its handle.
If an asset with the same name already exists, its data is replaced
in-place: the same slot-map entry (and therefore the same handle)
is reused, so any code that already holds a Handle
or RawAssetHandle for this asset continues to work correctly.
The handle is re-queued so the sync system re-uploads the new data.
Sourcepub fn get(&self, handle: RawAssetHandle) -> Option<&T>
pub fn get(&self, handle: RawAssetHandle) -> Option<&T>
Look up an asset by its raw handle.
Sourcepub fn get_mut(&mut self, handle: RawAssetHandle) -> Option<&mut T>
pub fn get_mut(&mut self, handle: RawAssetHandle) -> Option<&mut T>
Mutably look up an asset by its raw handle.
Sourcepub fn get_by_name(&self, name: &str) -> Option<&T>
pub fn get_by_name(&self, name: &str) -> Option<&T>
Look up an asset by its name.
Sourcepub fn get_mut_by_name(&mut self, name: &str) -> Option<&mut T>
pub fn get_mut_by_name(&mut self, name: &str) -> Option<&mut T>
Mutably look up an asset by its name.
Sourcepub fn get_handle_by_name(&self, name: &str) -> Option<RawAssetHandle>
pub fn get_handle_by_name(&self, name: &str) -> Option<RawAssetHandle>
Look up an asset handle by its name.
Sourcepub fn take_dirty(&mut self) -> Vec<RawAssetHandle>
pub fn take_dirty(&mut self) -> Vec<RawAssetHandle>
Drain and return all handles currently in the dirty queue.
Called by the asset sync system each tick.
Sourcepub fn remove(&mut self, handle: RawAssetHandle) -> Option<T>
pub fn remove(&mut self, handle: RawAssetHandle) -> Option<T>
Remove an asset by handle, returning the value if it existed.
Sourcepub fn remove_by_name(&mut self, name: &str) -> Option<T>
pub fn remove_by_name(&mut self, name: &str) -> Option<T>
Remove an asset by name, returning the value if it existed.
Sourcepub fn take_removed(&mut self) -> Vec<RawAssetHandle>
pub fn take_removed(&mut self) -> Vec<RawAssetHandle>
Drain and return all handles removed since the last call.
Called by the asset sync system each tick to evict stale processed assets.
Sourcepub fn dirty_is_empty(&self) -> bool
pub fn dirty_is_empty(&self) -> bool
Returns true if the dirty queue is empty.
Sourcepub fn requeue(&mut self, handles: Vec<RawAssetHandle>)
pub fn requeue(&mut self, handles: Vec<RawAssetHandle>)
Push handles back onto the dirty queue so they are retried next tick.
Sourcepub fn iter(&self) -> impl Iterator<Item = (RawAssetHandle, &T)>
pub fn iter(&self) -> impl Iterator<Item = (RawAssetHandle, &T)>
Iterate over all assets by handle.
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = (RawAssetHandle, &mut T)>
pub fn iter_mut(&mut self) -> impl Iterator<Item = (RawAssetHandle, &mut T)>
Mutably iterate over all assets by handle.
Sourcepub fn names(&self) -> impl Iterator<Item = (&str, RawAssetHandle)>
pub fn names(&self) -> impl Iterator<Item = (&str, RawAssetHandle)>
Iterate over (name, handle) pairs for every named asset.