Struct zengine_asset::Handle
source · [−]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
sourceimpl<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
sourceimpl<T: Asset> Ord for Handle<T>
impl<T: Asset> Ord for Handle<T>
1.21.0 · sourceconst fn max(self, other: Self) -> Self
const fn max(self, other: Self) -> Self
1.21.0 · sourceconst fn min(self, other: Self) -> Self
const fn min(self, other: Self) -> Self
1.50.0 · sourceconst fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
const fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
sourceimpl<T: Asset> PartialOrd<Handle<T>> for Handle<T>
impl<T: Asset> PartialOrd<Handle<T>> for Handle<T>
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
1.0.0 · sourceconst fn le(&self, other: &Rhs) -> bool
const fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl<T: Asset> Eq for Handle<T>
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
sourcefn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
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
. Read moresourcefn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read moresourcefn 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. Read moresourcefn 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. Read more