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
use query_flow::{asset_key, query, Db, DurabilityLevel, QueryError, QueryRuntime};
#[asset_key(asset = String)]
struct FilePath(String);
#[query]
fn process_file(db: &impl Db, path: FilePath) -> Result<usize, QueryError> {
// Most common: just use db.asset() which suspends automatically
let content = db.asset(path)?;
Ok(content.len())
}
#[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())
}
let runtime = QueryRuntime::new();
runtime.resolve_asset(
FilePath("a".into()),
"hello".into(),
DurabilityLevel::Volatile,
);
assert_eq!(*runtime.query(ProcessFile::new(FilePath("a".into()))).unwrap(), 5);
assert!(!*runtime.query(CheckLoading::new(FilePath("a".into()))).unwrap());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
use query_flow::{asset_key, query, Db, DurabilityLevel, QueryError, QueryRuntime};
#[asset_key(asset = String)]
struct FilePath(String);
#[query]
fn byte_len(db: &impl Db, path: FilePath) -> Result<usize, QueryError> {
// Preferred: use db.asset() directly
let data = db.asset(path.clone())?;
// Alternative: use asset_state() + suspend()
let state = db.asset_state(path)?;
let data2 = state.suspend()?;
assert_eq!(data, data2);
Ok(data.len())
}
let runtime = QueryRuntime::new();
runtime.resolve_asset(
FilePath("a".into()),
"hello".into(),
DurabilityLevel::Volatile,
);
assert_eq!(*runtime.query(ByteLen::new(FilePath("a".into()))).unwrap(), 5);Trait Implementations§
Auto Trait Implementations§
impl<K> Freeze for AssetLoadingState<K>
impl<K> RefUnwindSafe for AssetLoadingState<K>
impl<K> Send for AssetLoadingState<K>
impl<K> Sync for AssetLoadingState<K>
impl<K> Unpin for AssetLoadingState<K>
impl<K> UnsafeUnpin for AssetLoadingState<K>
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