#[repr(u8)]pub enum AssetState {
NotLoaded = 0,
Loading {
progress: f32,
},
Loaded = 2,
Failed {
error: String,
},
Unloaded = 4,
}Expand description
Loading state of an asset.
Tracks the lifecycle of an asset from initial request to loaded (or failed). Used by the asset server to report loading progress.
§State Transitions
NotLoaded ──▶ Loading ──▶ Loaded
│
└──▶ Failed§FFI Safety
This enum is #[repr(u8)] for stable, FFI-compatible representation.
§Example
use goud_engine::assets::AssetState;
let state = AssetState::Loading { progress: 0.5 };
match state {
AssetState::Loading { progress } => {
println!("Loading: {}%", progress * 100.0);
}
AssetState::Loaded => println!("Ready!"),
AssetState::Failed { .. } => println!("Error!"),
_ => {}
}Variants§
NotLoaded = 0
Asset has not been requested for loading.
Loading
Asset is currently being loaded.
Progress is a value from 0.0 to 1.0.
Loaded = 2
Asset has been successfully loaded and is ready for use.
Failed
Asset loading failed.
Unloaded = 4
Asset was loaded but has been unloaded from memory.
Implementations§
Source§impl AssetState
impl AssetState
Sourcepub fn is_ready(&self) -> bool
pub fn is_ready(&self) -> bool
Returns true if the asset is ready for use.
§Example
use goud_engine::assets::AssetState;
assert!(AssetState::Loaded.is_ready());
assert!(!AssetState::Loading { progress: 0.5 }.is_ready());Sourcepub fn is_loading(&self) -> bool
pub fn is_loading(&self) -> bool
Returns true if the asset is currently loading.
§Example
use goud_engine::assets::AssetState;
assert!(AssetState::Loading { progress: 0.5 }.is_loading());
assert!(!AssetState::Loaded.is_loading());Sourcepub fn is_failed(&self) -> bool
pub fn is_failed(&self) -> bool
Returns true if asset loading failed.
§Example
use goud_engine::assets::AssetState;
let state = AssetState::Failed { error: "File not found".to_string() };
assert!(state.is_failed());Sourcepub fn progress(&self) -> Option<f32>
pub fn progress(&self) -> Option<f32>
Returns the loading progress if currently loading.
Returns None for non-loading states.
§Example
use goud_engine::assets::AssetState;
let state = AssetState::Loading { progress: 0.75 };
assert_eq!(state.progress(), Some(0.75));
assert_eq!(AssetState::Loaded.progress(), None);Sourcepub fn error(&self) -> Option<&str>
pub fn error(&self) -> Option<&str>
Returns the error message if loading failed.
Returns None for non-failed states.
§Example
use goud_engine::assets::AssetState;
let state = AssetState::Failed { error: "Invalid format".to_string() };
assert_eq!(state.error(), Some("Invalid format"));
assert_eq!(AssetState::Loaded.error(), None);Sourcepub fn discriminant(&self) -> u8
pub fn discriminant(&self) -> u8
Returns the discriminant as a u8 for FFI.
§Example
use goud_engine::assets::AssetState;
assert_eq!(AssetState::NotLoaded.discriminant(), 0);
assert_eq!(AssetState::Loading { progress: 0.0 }.discriminant(), 1);
assert_eq!(AssetState::Loaded.discriminant(), 2);Trait Implementations§
Source§impl Clone for AssetState
impl Clone for AssetState
Source§fn clone(&self) -> AssetState
fn clone(&self) -> AssetState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AssetState
impl Debug for AssetState
Source§impl Default for AssetState
impl Default for AssetState
Source§fn default() -> AssetState
fn default() -> AssetState
Source§impl Display for AssetState
impl Display for AssetState
Source§impl PartialEq for AssetState
impl PartialEq for AssetState
impl StructuralPartialEq for AssetState
Auto Trait Implementations§
impl Freeze for AssetState
impl RefUnwindSafe for AssetState
impl Send for AssetState
impl Sync for AssetState
impl Unpin for AssetState
impl UnsafeUnpin for AssetState
impl UnwindSafe for AssetState
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().