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
impl AssetStorage
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new asset storage with pre-allocated capacity for storage map.
Sourcepub fn insert<A: Asset>(&mut self, asset: A) -> AssetHandle<A>
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.
Sourcepub fn insert_with_path<A: Asset>(
&mut self,
asset: A,
path: AssetPath<'_>,
) -> AssetHandle<A>
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.
Sourcepub fn reserve<A: Asset>(&mut self) -> AssetHandle<A>
pub fn reserve<A: Asset>(&mut self) -> AssetHandle<A>
Reserves a handle for later loading.
Sourcepub fn reserve_with_path<A: Asset>(
&mut self,
path: AssetPath<'_>,
) -> AssetHandle<A>
pub fn reserve_with_path<A: Asset>( &mut self, path: AssetPath<'_>, ) -> AssetHandle<A>
Reserves a handle with an associated path.
Sourcepub fn set_loaded<A: Asset>(
&mut self,
handle: &AssetHandle<A>,
asset: A,
) -> bool
pub fn set_loaded<A: Asset>( &mut self, handle: &AssetHandle<A>, asset: A, ) -> bool
Sets a loaded asset for a reserved handle.
Sourcepub fn remove<A: Asset>(&mut self, handle: &AssetHandle<A>) -> Option<A>
pub fn remove<A: Asset>(&mut self, handle: &AssetHandle<A>) -> Option<A>
Removes an asset and returns it.
Sourcepub fn remove_untyped(&mut self, handle: &UntypedAssetHandle) -> bool
pub fn remove_untyped(&mut self, handle: &UntypedAssetHandle) -> bool
Removes an asset by untyped handle.
Sourcepub fn get<A: Asset>(&self, handle: &AssetHandle<A>) -> Option<&A>
pub fn get<A: Asset>(&self, handle: &AssetHandle<A>) -> Option<&A>
Gets a reference to an asset.
Sourcepub fn get_mut<A: Asset>(&mut self, handle: &AssetHandle<A>) -> Option<&mut A>
pub fn get_mut<A: Asset>(&mut self, handle: &AssetHandle<A>) -> Option<&mut A>
Gets a mutable reference to an asset.
Sourcepub fn get_entry<A: Asset>(
&self,
handle: &AssetHandle<A>,
) -> Option<&AssetEntry<A>>
pub fn get_entry<A: Asset>( &self, handle: &AssetHandle<A>, ) -> Option<&AssetEntry<A>>
Gets the entry for a handle.
Sourcepub fn get_entry_mut<A: Asset>(
&mut self,
handle: &AssetHandle<A>,
) -> Option<&mut AssetEntry<A>>
pub fn get_entry_mut<A: Asset>( &mut self, handle: &AssetHandle<A>, ) -> Option<&mut AssetEntry<A>>
Gets the mutable entry for a handle.
Sourcepub fn is_alive<A: Asset>(&self, handle: &AssetHandle<A>) -> bool
pub fn is_alive<A: Asset>(&self, handle: &AssetHandle<A>) -> bool
Checks if a handle is alive.
Sourcepub fn is_alive_untyped(&self, handle: &UntypedAssetHandle) -> bool
pub fn is_alive_untyped(&self, handle: &UntypedAssetHandle) -> bool
Checks if an untyped handle is alive.
Sourcepub fn get_state<A: Asset>(&self, handle: &AssetHandle<A>) -> Option<AssetState>
pub fn get_state<A: Asset>(&self, handle: &AssetHandle<A>) -> Option<AssetState>
Gets the state for a handle.
Sourcepub fn get_state_untyped(
&self,
handle: &UntypedAssetHandle,
) -> Option<AssetState>
pub fn get_state_untyped( &self, handle: &UntypedAssetHandle, ) -> Option<AssetState>
Gets the state for an untyped handle.
Sourcepub fn get_handle_by_path<A: Asset>(&self, path: &str) -> Option<AssetHandle<A>>
pub fn get_handle_by_path<A: Asset>(&self, path: &str) -> Option<AssetHandle<A>>
Gets a handle by path.
Sourcepub fn has_path<A: Asset>(&self, path: &str) -> bool
pub fn has_path<A: Asset>(&self, path: &str) -> bool
Checks if a path exists for an asset type.
Sourcepub fn set_path<A: Asset>(
&mut self,
handle: &AssetHandle<A>,
path: AssetPath<'_>,
) -> bool
pub fn set_path<A: Asset>( &mut self, handle: &AssetHandle<A>, path: AssetPath<'_>, ) -> bool
Sets the path for a handle.
Sourcepub fn is_empty_type<A: Asset>(&self) -> bool
pub fn is_empty_type<A: Asset>(&self) -> bool
Returns true if no assets of a specific type are stored.
Sourcepub fn type_count(&self) -> usize
pub fn type_count(&self) -> usize
Returns the number of registered asset types.
Sourcepub fn clear_type<A: Asset>(&mut self)
pub fn clear_type<A: Asset>(&mut self)
Clears all assets of a specific type.
Sourcepub fn registered_types(&self) -> Vec<AssetInfo>
pub fn registered_types(&self) -> Vec<AssetInfo>
Returns asset info for all registered types.
Sourcepub fn get_storage<A: Asset>(&self) -> Option<&TypedAssetStorage<A>>
pub fn get_storage<A: Asset>(&self) -> Option<&TypedAssetStorage<A>>
Gets the typed storage for an asset type.
Sourcepub fn get_storage_mut<A: Asset>(&mut self) -> Option<&mut TypedAssetStorage<A>>
pub fn get_storage_mut<A: Asset>(&mut self) -> Option<&mut TypedAssetStorage<A>>
Gets mutable typed storage for an asset type.
Sourcepub fn set_loaded_raw(
&mut self,
asset_id: AssetId,
index: u32,
generation: u32,
boxed: Box<dyn Any + Send>,
) -> bool
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.
Sourcepub fn replace_erased(&mut self, path: &str, boxed: Box<dyn Any + Send>) -> bool
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.
Sourcepub fn set_failed_raw(
&mut self,
asset_id: AssetId,
index: u32,
generation: u32,
error: String,
) -> bool
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.
Sourcepub fn get_or_create_storage<A: Asset>(&mut self) -> &mut TypedAssetStorage<A>
pub fn get_or_create_storage<A: Asset>(&mut self) -> &mut TypedAssetStorage<A>
Gets or creates typed storage for an asset type.
Sourcepub fn iter<A: Asset>(&self) -> impl Iterator<Item = (AssetHandle<A>, &A)>
pub fn iter<A: Asset>(&self) -> impl Iterator<Item = (AssetHandle<A>, &A)>
Iterates over all assets of a specific type.
Sourcepub fn handles<A: Asset>(&self) -> impl Iterator<Item = AssetHandle<A>> + '_
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
impl Debug for AssetStorage
Auto Trait Implementations§
impl Freeze for AssetStorage
impl !RefUnwindSafe for AssetStorage
impl Send for AssetStorage
impl Sync for AssetStorage
impl Unpin for AssetStorage
impl UnsafeUnpin for AssetStorage
impl !UnwindSafe for AssetStorage
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
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>
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>
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>
ReadEndian::read_from_little_endian().