pub struct Handle<T> { /* private fields */ }Expand description
A handle into a specific Asset of type T
Handles contain a unique id that corresponds to a specific asset in the Assets collection.
§Accessing the Asset
A handle is not the asset itself, it’s mora like a pointer to the asset.
To get the actual asset, you should use Assets::get or Assets::get_mut.
§Strong and Weak
A handle can be either “Strong” or “Weak”. A Strong handles keep the asset loaded.
A Weak handles do not affect the loaded status of assets.
This is due to a type of_reference counting_. When the number of Strong handles that exist for any given asset reach zero, the asset is dropped and will be unloaded.
If you want a reference to an asset but don’t want to take the responsibility of keeping it loaded that comes with a Strong handle then you need a Weak handle.
Implementations§
Source§impl<T: Asset> Handle<T>
impl<T: Asset> Handle<T>
Sourcepub fn clone_as_weak(&self) -> Self
pub fn clone_as_weak(&self) -> Self
Clone the handle producing a weak one that point to the same asset
Sourcepub fn make_strong(&mut self, assets: &Assets<T>)
pub fn make_strong(&mut self, assets: &Assets<T>)
Makes this handle Strong if it wasn’t already
This method requires the corresponding Assets storage
Trait Implementations§
Source§impl<T: Asset> Ord for Handle<T>
impl<T: Asset> Ord for Handle<T>
Source§impl<T: Asset> PartialOrd for Handle<T>
impl<T: Asset> PartialOrd for Handle<T>
impl<T: Asset> Eq for Handle<T>
Auto Trait Implementations§
impl<T> Freeze for Handle<T>
impl<T> RefUnwindSafe for Handle<T>where
T: RefUnwindSafe,
impl<T> Send for Handle<T>where
T: Send,
impl<T> Sync for Handle<T>where
T: Sync,
impl<T> Unpin for Handle<T>where
T: Unpin,
impl<T> UnwindSafe for Handle<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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.