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

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).

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