AssetLoadingState

Struct AssetLoadingState 

Source
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>

Source

pub fn loading(key: K) -> Self

Create a loading state (asset not yet available).

Source

pub fn ready(key: K, value: Arc<K::Asset>) -> Self

Create a ready state with the asset value.

Source

pub fn is_loading(&self) -> bool

Check if the resource is still loading.

Source

pub fn is_ready(&self) -> bool

Check if the resource is ready.

Source

pub fn get(&self) -> Option<&Arc<K::Asset>>

Get the value if ready, None if loading.

Source

pub fn into_inner(self) -> Option<Arc<K::Asset>>

Get the value if ready, None if loading (consuming version).

Source

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))
}
Source

pub fn key(&self) -> &K

Get a reference to the key.

Trait Implementations§

Source§

impl<K: AssetKey> Debug for AssetLoadingState<K>
where K::Asset: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.