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 replace(&mut self, handle: RawAssetHandle, asset: T) -> bool
pub fn replace(&mut self, handle: RawAssetHandle, asset: T) -> bool
Replace the data for an existing asset by handle, re-queuing it for
upload. Returns false if the handle is null or not present.
This is the handle-based counterpart to insert: use it
when you already have the handle and don’t need to go through a name
lookup. The handle stays valid — only the underlying data changes.
Sourcepub fn mark_dirty(&mut self, handle: RawAssetHandle)
pub fn mark_dirty(&mut self, handle: RawAssetHandle)
Mark a single asset as dirty so the sync system re-uploads it next tick, even though its source data has not changed.
Use this when a resource the asset depends on has been recreated (e.g. a texture that a material instance’s bind group references was resized), requiring the processed asset to be rebuilt with the new version.
Does nothing if handle is null or not present in this store.
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.
pub fn name_for_handle(&self, handle: RawAssetHandle) -> Option<&str>
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Assets<T>
impl<T> RefUnwindSafe for Assets<T>where
T: RefUnwindSafe,
impl<T> Send for Assets<T>
impl<T> Sync for Assets<T>
impl<T> Unpin for Assets<T>where
T: Unpin,
impl<T> UnsafeUnpin for Assets<T>
impl<T> UnwindSafe for Assets<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> Component for T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more