pub struct QueryContext<'a> { /* private fields */ }Expand description
Context provided to queries during execution.
Use this to access dependencies via query().
Implementations§
Source§impl<'a> QueryContext<'a>
impl<'a> QueryContext<'a>
Sourcepub fn asset<K: AssetKey>(
&mut self,
key: &K,
) -> Result<LoadingState<Arc<K::Asset>>, QueryError>
pub fn asset<K: AssetKey>( &mut self, key: &K, ) -> Result<LoadingState<Arc<K::Asset>>, QueryError>
Access an asset, tracking it as a dependency.
Returns LoadingState<Arc<K::Asset>>:
LoadingState::Loadingif the asset is still being loadedLoadingState::Ready(value)if the asset is available
§Example
ⓘ
#[query]
fn process_file(ctx: &mut QueryContext, path: FilePath) -> Result<Output, QueryError> {
let content = ctx.asset(&path)?.suspend()?;
// Process content...
Ok(output)
}§Errors
Returns Err(QueryError::MissingDependency) if the asset was not found.
Sourcepub fn list_queries<Q: Query>(&mut self) -> Vec<Q>
pub fn list_queries<Q: Query>(&mut self) -> Vec<Q>
List all query instances of type Q that have been registered.
This method establishes a dependency on the “set” of queries of type Q. The calling query will be invalidated when:
- A new query of type Q is first executed (added to set)
The calling query will NOT be invalidated when:
- An individual query of type Q has its value change
§Example
ⓘ
#[query]
fn all_results(ctx: &mut QueryContext) -> Result<Vec<i32>, QueryError> {
let queries = ctx.list_queries::<MyQuery>();
let mut results = Vec::new();
for q in queries {
results.push(*ctx.query(q)?);
}
Ok(results)
}Sourcepub fn list_asset_keys<K: AssetKey>(&mut self) -> Vec<K>
pub fn list_asset_keys<K: AssetKey>(&mut self) -> Vec<K>
List all asset keys of type K that have been registered.
This method establishes a dependency on the “set” of asset keys of type K. The calling query will be invalidated when:
- A new asset of type K is resolved for the first time (added to set)
- An asset of type K is removed via remove_asset
The calling query will NOT be invalidated when:
- An individual asset’s value changes (use
ctx.asset()for that)
§Example
ⓘ
#[query]
fn all_configs(ctx: &mut QueryContext) -> Result<Vec<String>, QueryError> {
let keys = ctx.list_asset_keys::<ConfigFile>();
let mut contents = Vec::new();
for key in keys {
let content = ctx.asset(&key)?.suspend()?;
contents.push((*content).clone());
}
Ok(contents)
}Auto Trait Implementations§
impl<'a> !Freeze for QueryContext<'a>
impl<'a> !RefUnwindSafe for QueryContext<'a>
impl<'a> Send for QueryContext<'a>
impl<'a> !Sync for QueryContext<'a>
impl<'a> Unpin for QueryContext<'a>
impl<'a> UnwindSafe for QueryContext<'a>
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