Assets

Struct Assets 

Source
pub struct Assets<A: Asset> { /* private fields */ }
Expand description

A central, in-memory cache for a specific type of asset A.

This structure maps a unique AssetUUID to a shared AssetHandle<A>. This ensures that any given asset is loaded only once. Subsequent requests for the same asset will receive a clone of the cached handle.

Implementations§

Source§

impl<A: Asset> Assets<A>

Source

pub fn new() -> Self

Creates a new, empty asset storage.

Source

pub fn insert(&mut self, uuid: AssetUUID, handle: AssetHandle<A>)

Inserts an asset handle into the storage, associated with its UUID. If an asset with the same UUID already exists, it will be replaced. This operation is always successful.

§Arguments
  • uuid - The unique identifier for the asset.
  • handle - The handle to the asset to be stored.
Source

pub fn get(&self, uuid: &AssetUUID) -> Option<&AssetHandle<A>>

Retrieves a reference to the asset handle associated with the given UUID. Returns None if no asset with the specified UUID is found.

Source

pub fn contains(&self, uuid: &AssetUUID) -> bool

Checks if an asset with the specified UUID exists in the storage.

Trait Implementations§

Source§

impl<A: Default + Asset> Default for Assets<A>

Source§

fn default() -> Assets<A>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<A> Freeze for Assets<A>

§

impl<A> RefUnwindSafe for Assets<A>
where A: RefUnwindSafe,

§

impl<A> Send for Assets<A>

§

impl<A> Sync for Assets<A>

§

impl<A> Unpin for Assets<A>

§

impl<A> UnwindSafe for Assets<A>
where A: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.