Skip to main content

AssetStorage

Struct AssetStorage 

Source
pub struct AssetStorage { /* private fields */ }
Expand description

Type-erased container for all asset types.

AssetStorage is the main asset storage container that holds typed storages for each registered asset type. It provides both typed and untyped access patterns.

§Example

use goud_engine::assets::{Asset, AssetStorage, AssetPath};

struct Texture { width: u32 }
impl Asset for Texture {}

struct Audio { duration: f32 }
impl Asset for Audio {}

let mut storage = AssetStorage::new();

// Insert different asset types
let tex_handle = storage.insert(Texture { width: 256 });
let audio_handle = storage.insert(Audio { duration: 2.5 });

// Type-safe access
assert_eq!(storage.get::<Texture>(&tex_handle).unwrap().width, 256);
assert_eq!(storage.get::<Audio>(&audio_handle).unwrap().duration, 2.5);

// Count by type
assert_eq!(storage.len::<Texture>(), 1);
assert_eq!(storage.len::<Audio>(), 1);

Implementations§

Source§

impl AssetStorage

Source

pub fn new() -> Self

Creates a new, empty asset storage.

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new asset storage with pre-allocated capacity for storage map.

Source

pub fn insert<A: Asset>(&mut self, asset: A) -> AssetHandle<A>

Inserts an asset and returns its handle.

Automatically creates the typed storage if it doesn’t exist.

Source

pub fn insert_with_path<A: Asset>( &mut self, asset: A, path: AssetPath<'_>, ) -> AssetHandle<A>

Inserts an asset with an associated path.

If an asset with the same path exists and is alive, returns the existing handle.

Source

pub fn reserve<A: Asset>(&mut self) -> AssetHandle<A>

Reserves a handle for later loading.

Source

pub fn reserve_with_path<A: Asset>( &mut self, path: AssetPath<'_>, ) -> AssetHandle<A>

Reserves a handle with an associated path.

Source

pub fn set_loaded<A: Asset>( &mut self, handle: &AssetHandle<A>, asset: A, ) -> bool

Sets a loaded asset for a reserved handle.

Source

pub fn remove<A: Asset>(&mut self, handle: &AssetHandle<A>) -> Option<A>

Removes an asset and returns it.

Source

pub fn remove_untyped(&mut self, handle: &UntypedAssetHandle) -> bool

Removes an asset by untyped handle.

Source

pub fn get<A: Asset>(&self, handle: &AssetHandle<A>) -> Option<&A>

Gets a reference to an asset.

Source

pub fn get_mut<A: Asset>(&mut self, handle: &AssetHandle<A>) -> Option<&mut A>

Gets a mutable reference to an asset.

Source

pub fn get_entry<A: Asset>( &self, handle: &AssetHandle<A>, ) -> Option<&AssetEntry<A>>

Gets the entry for a handle.

Source

pub fn get_entry_mut<A: Asset>( &mut self, handle: &AssetHandle<A>, ) -> Option<&mut AssetEntry<A>>

Gets the mutable entry for a handle.

Source

pub fn is_alive<A: Asset>(&self, handle: &AssetHandle<A>) -> bool

Checks if a handle is alive.

Source

pub fn is_alive_untyped(&self, handle: &UntypedAssetHandle) -> bool

Checks if an untyped handle is alive.

Source

pub fn get_state<A: Asset>(&self, handle: &AssetHandle<A>) -> Option<AssetState>

Gets the state for a handle.

Source

pub fn get_state_untyped( &self, handle: &UntypedAssetHandle, ) -> Option<AssetState>

Gets the state for an untyped handle.

Source

pub fn get_handle_by_path<A: Asset>(&self, path: &str) -> Option<AssetHandle<A>>

Gets a handle by path.

Source

pub fn get_by_path<A: Asset>(&self, path: &str) -> Option<&A>

Gets an asset by path.

Source

pub fn has_path<A: Asset>(&self, path: &str) -> bool

Checks if a path exists for an asset type.

Source

pub fn set_path<A: Asset>( &mut self, handle: &AssetHandle<A>, path: AssetPath<'_>, ) -> bool

Sets the path for a handle.

Source

pub fn len<A: Asset>(&self) -> usize

Returns the number of assets of a specific type.

Source

pub fn is_empty_type<A: Asset>(&self) -> bool

Returns true if no assets of a specific type are stored.

Source

pub fn total_len(&self) -> usize

Returns the total number of assets across all types.

Source

pub fn is_empty(&self) -> bool

Returns true if no assets are stored.

Source

pub fn type_count(&self) -> usize

Returns the number of registered asset types.

Source

pub fn clear_type<A: Asset>(&mut self)

Clears all assets of a specific type.

Source

pub fn clear(&mut self)

Clears all assets from all storages.

Source

pub fn has_type<A: Asset>(&self) -> bool

Returns true if storage exists for a type.

Source

pub fn registered_types(&self) -> Vec<AssetInfo>

Returns asset info for all registered types.

Source

pub fn get_storage<A: Asset>(&self) -> Option<&TypedAssetStorage<A>>

Gets the typed storage for an asset type.

Source

pub fn get_storage_mut<A: Asset>(&mut self) -> Option<&mut TypedAssetStorage<A>>

Gets mutable typed storage for an asset type.

Source

pub fn set_loaded_raw( &mut self, asset_id: AssetId, index: u32, generation: u32, boxed: Box<dyn Any + Send>, ) -> bool

Sets a loaded asset from a type-erased boxed value using raw handle parts.

Used by async loading to finalize results on the main thread.

Source

pub fn replace_erased(&mut self, path: &str, boxed: Box<dyn Any + Send>) -> bool

Replaces a loaded asset by path with a new type-erased value.

Searches all storage types for an asset with the given path and replaces it with the new value. Used for hot-reload.

Source

pub fn set_failed_raw( &mut self, asset_id: AssetId, index: u32, generation: u32, error: String, ) -> bool

Marks an asset as failed using raw handle parts.

Used by async loading to report errors on the main thread.

Source

pub fn get_or_create_storage<A: Asset>(&mut self) -> &mut TypedAssetStorage<A>

Gets or creates typed storage for an asset type.

Source

pub fn iter<A: Asset>(&self) -> impl Iterator<Item = (AssetHandle<A>, &A)>

Iterates over all assets of a specific type.

Source

pub fn handles<A: Asset>(&self) -> impl Iterator<Item = AssetHandle<A>> + '_

Returns handles for all assets of a specific type.

Trait Implementations§

Source§

impl Debug for AssetStorage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AssetStorage

Source§

fn default() -> Self

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

Auto Trait Implementations§

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<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

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().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> Event for T
where T: Send + Sync + 'static,

Source§

impl<T> Resource for T
where T: Send + Sync + 'static,