pub struct AssetHandle<T: Asset>(/* private fields */);
Expand description
A thread-safe, reference-counted handle to a loaded asset’s data.
This struct acts as a smart pointer that provides shared ownership of asset data in memory. It is the primary way that game logic and systems should interact with loaded assets.
Cloning an AssetHandle
is a very cheap operation, as it only increments an
atomic reference counter. It does not duplicate the underlying asset data. The
asset data is automatically deallocated when the last handle pointing to it
is dropped.
This handle dereferences to &T
, allowing for transparent, read-only access
to the asset’s contents.
§Examples
let texture = Texture {};
// The AssetAgent creates the first handle when loading is complete.
let handle1 = AssetHandle::new(texture);
// Other systems can clone the handle to share access.
let handle2 = handle1.clone();
// Accessing the data is done via dereferencing (like with `Arc` or `Box`).
// let width = handle1.width; // Assuming Texture has a `width` field.
Implementations§
Trait Implementations§
Source§impl<T: Asset> Clone for AssetHandle<T>
impl<T: Asset> Clone for AssetHandle<T>
Auto Trait Implementations§
impl<T> Freeze for AssetHandle<T>
impl<T> RefUnwindSafe for AssetHandle<T>where
T: RefUnwindSafe,
impl<T> Send for AssetHandle<T>
impl<T> Sync for AssetHandle<T>
impl<T> Unpin for AssetHandle<T>
impl<T> UnwindSafe for AssetHandle<T>where
T: RefUnwindSafe,
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