pub struct AssetLoadingState<K: AssetKey> { /* private fields */ }Expand description
Loading state with asset key information for error reporting.
This is returned by Db::asset_state() and provides
information about whether an asset is loading or ready.
For most use cases, prefer Db::asset() which automatically
suspends on loading. Use asset_state() when you need to explicitly check
the loading state without triggering suspension.
§Example
ⓘ
#[query]
fn process_file(db: &impl Db, path: FilePath) -> Result<Output, QueryError> {
// Most common: just use db.asset() which suspends automatically
let content = db.asset(path)?;
Ok(process(&content))
}
#[query]
fn check_loading(db: &impl Db, path: FilePath) -> Result<bool, QueryError> {
// Use asset_state() when you need to check loading status explicitly
let state = db.asset_state(path)?;
Ok(state.is_loading())
}Implementations§
Source§impl<K: AssetKey> AssetLoadingState<K>
impl<K: AssetKey> AssetLoadingState<K>
Sourcepub fn is_loading(&self) -> bool
pub fn is_loading(&self) -> bool
Check if the resource is still loading.
Sourcepub fn into_inner(self) -> Option<Arc<K::Asset>>
pub fn into_inner(self) -> Option<Arc<K::Asset>>
Get the value if ready, None if loading (consuming version).
Sourcepub fn suspend(self) -> Result<Arc<K::Asset>, QueryError>
pub fn suspend(self) -> Result<Arc<K::Asset>, QueryError>
Convert to Result - Loading becomes Err(QueryError::Suspend).
This method is used internally by Db::asset().
You can also use it when working with Db::asset_state().
§Example
ⓘ
fn query(&self, db: &impl Db) -> Result<MyOutput, QueryError> {
// Preferred: use db.asset() directly
let data = db.asset(key)?;
// Alternative: use asset_state() + suspend()
let state = db.asset_state(key)?;
let data = state.suspend()?;
Ok(process(&data))
}Trait Implementations§
Auto Trait Implementations§
impl<K> Freeze for AssetLoadingState<K>where
K: Freeze,
impl<K> RefUnwindSafe for AssetLoadingState<K>
impl<K> Send for AssetLoadingState<K>
impl<K> Sync for AssetLoadingState<K>
impl<K> Unpin for AssetLoadingState<K>where
K: Unpin,
impl<K> UnwindSafe for AssetLoadingState<K>
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
Mutably borrows from an owned value. Read more