pub struct WeakAssetHandle<A: Asset> { /* private fields */ }Expand description
A weak reference to an asset that doesn’t prevent unloading.
Unlike AssetHandle, a WeakAssetHandle does not contribute to the
reference count of an asset. This is useful for caches and lookup tables
where you want to reference assets without keeping them loaded.
§Example
use goud_engine::assets::{Asset, AssetHandle, WeakAssetHandle};
struct Texture;
impl Asset for Texture {}
let strong: AssetHandle<Texture> = AssetHandle::new(1, 1);
let weak: WeakAssetHandle<Texture> = WeakAssetHandle::from_handle(&strong);
assert!(weak.is_valid());
assert_eq!(weak.index(), 1);
assert_eq!(weak.generation(), 1);
// Upgrade to strong handle for access (liveness must be checked separately)
let upgraded = weak.upgrade();
assert_eq!(upgraded.index(), 1);Implementations§
Source§impl<A: Asset> WeakAssetHandle<A>
impl<A: Asset> WeakAssetHandle<A>
Sourcepub fn from_handle(handle: &AssetHandle<A>) -> Self
pub fn from_handle(handle: &AssetHandle<A>) -> Self
Creates a weak handle from a strong handle.
Sourcepub const fn new(index: u32, generation: u32) -> Self
pub const fn new(index: u32, generation: u32) -> Self
Creates a new weak handle with the given index and generation.
Sourcepub const fn generation(&self) -> u32
pub const fn generation(&self) -> u32
Returns the generation component.
Sourcepub fn upgrade(&self) -> AssetHandle<A>
pub fn upgrade(&self) -> AssetHandle<A>
Upgrades to a strong handle.
Note: This does NOT check if the asset is still alive. Use
AssetServer::is_alive() to check liveness before using the handle.
Trait Implementations§
Source§impl<A: Asset> Clone for WeakAssetHandle<A>
impl<A: Asset> Clone for WeakAssetHandle<A>
Source§impl<A: Asset> Debug for WeakAssetHandle<A>
impl<A: Asset> Debug for WeakAssetHandle<A>
Source§impl<A: Asset> Default for WeakAssetHandle<A>
impl<A: Asset> Default for WeakAssetHandle<A>
Source§impl<A: Asset> From<&AssetHandle<A>> for WeakAssetHandle<A>
impl<A: Asset> From<&AssetHandle<A>> for WeakAssetHandle<A>
Source§fn from(handle: &AssetHandle<A>) -> Self
fn from(handle: &AssetHandle<A>) -> Self
Converts to this type from the input type.
Source§impl<A: Asset> Hash for WeakAssetHandle<A>
impl<A: Asset> Hash for WeakAssetHandle<A>
Source§impl<A: Asset> PartialEq for WeakAssetHandle<A>
impl<A: Asset> PartialEq for WeakAssetHandle<A>
impl<A: Asset> Copy for WeakAssetHandle<A>
impl<A: Asset> Eq for WeakAssetHandle<A>
Auto Trait Implementations§
impl<A> Freeze for WeakAssetHandle<A>
impl<A> RefUnwindSafe for WeakAssetHandle<A>where
A: RefUnwindSafe,
impl<A> Send for WeakAssetHandle<A>
impl<A> Sync for WeakAssetHandle<A>
impl<A> Unpin for WeakAssetHandle<A>where
A: Unpin,
impl<A> UnsafeUnpin for WeakAssetHandle<A>
impl<A> UnwindSafe for WeakAssetHandle<A>where
A: 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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
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>
Converts
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>
Converts
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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().