pub struct AssetLoadingState<K: AssetKey> { /* private fields */ }Expand description
Loading state with asset key information for error reporting.
This is returned by ctx.asset() and provides information about
whether an asset is loading or ready, along with the key for
error reporting on suspend.
§Example
ⓘ
#[query]
fn process_file(ctx: &mut QueryContext, path: FilePath) -> Result<Output, QueryError> {
let content = ctx.asset(path)?.suspend()?;
// Process content...
Ok(output)
}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).
Use this with the ? operator to propagate loading state upward.
The returned error includes the asset key for debugging.
§Example
ⓘ
fn query(&self, ctx: &mut QueryContext) -> Result<MyOutput, QueryError> {
let data = ctx.asset(key)?.suspend()?;
// `data` is guaranteed to be ready here
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