pub struct AssetEntry<A: Asset> { /* private fields */ }Expand description
An individual asset entry in storage with metadata.
AssetEntry wraps an asset value together with its loading state,
optional path association, and other metadata.
§Example
use goud_engine::assets::{Asset, AssetEntry, AssetState, AssetPath};
struct Texture { width: u32 }
impl Asset for Texture {}
// Create a loaded entry
let entry = AssetEntry::loaded(Texture { width: 256 });
assert!(entry.is_loaded());
assert_eq!(entry.asset().unwrap().width, 256);
// Create entry with path
let entry = AssetEntry::with_path(
Texture { width: 512 },
AssetPath::new("textures/player.png"),
);
assert_eq!(entry.path().map(|p| p.as_str()), Some("textures/player.png"));Implementations§
Source§impl<A: Asset> AssetEntry<A>
impl<A: Asset> AssetEntry<A>
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Creates a new entry in the NotLoaded state.
Use this when you want to reserve a handle before the asset is loaded.
Sourcepub fn loading(progress: f32) -> Self
pub fn loading(progress: f32) -> Self
Creates a new entry with a loading state.
§Arguments
progress- Initial loading progress (0.0 to 1.0)
Sourcepub fn with_path(asset: A, path: AssetPath<'static>) -> Self
pub fn with_path(asset: A, path: AssetPath<'static>) -> Self
Creates a new entry with a loaded asset and path.
Sourcepub fn failed(error: impl Into<String>) -> Self
pub fn failed(error: impl Into<String>) -> Self
Creates a new failed entry with an error message.
Sourcepub fn asset_mut(&mut self) -> Option<&mut A>
pub fn asset_mut(&mut self) -> Option<&mut A>
Returns a mutable reference to the asset if loaded.
Sourcepub fn take_asset(&mut self) -> Option<A>
pub fn take_asset(&mut self) -> Option<A>
Takes the asset out of this entry, leaving None.
Sourcepub fn state(&self) -> &AssetState
pub fn state(&self) -> &AssetState
Returns a reference to the current state.
Sourcepub fn path(&self) -> Option<&AssetPath<'static>>
pub fn path(&self) -> Option<&AssetPath<'static>>
Returns the path this asset was loaded from, if any.
Sourcepub fn clear_path(&mut self)
pub fn clear_path(&mut self)
Clears the path for this entry.
Sourcepub fn is_loading(&self) -> bool
pub fn is_loading(&self) -> bool
Returns true if the asset is currently loading.
Sourcepub fn set_loaded(&mut self, asset: A)
pub fn set_loaded(&mut self, asset: A)
Sets the asset and marks as loaded.
Sourcepub fn set_progress(&mut self, progress: f32)
pub fn set_progress(&mut self, progress: f32)
Updates the loading progress.
Sourcepub fn set_failed(&mut self, error: impl Into<String>)
pub fn set_failed(&mut self, error: impl Into<String>)
Marks the entry as failed.
Sourcepub fn set_unloaded(&mut self)
pub fn set_unloaded(&mut self)
Marks the entry as unloaded and removes the asset.
Trait Implementations§
Source§impl<A: Clone + Asset> Clone for AssetEntry<A>
impl<A: Clone + Asset> Clone for AssetEntry<A>
Source§fn clone(&self) -> AssetEntry<A>
fn clone(&self) -> AssetEntry<A>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<A> Freeze for AssetEntry<A>where
A: Freeze,
impl<A> RefUnwindSafe for AssetEntry<A>where
A: RefUnwindSafe,
impl<A> Send for AssetEntry<A>
impl<A> Sync for AssetEntry<A>
impl<A> Unpin for AssetEntry<A>where
A: Unpin,
impl<A> UnsafeUnpin for AssetEntry<A>where
A: UnsafeUnpin,
impl<A> UnwindSafe for AssetEntry<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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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().