pub trait AssetKey: Key + 'static {
type Asset: Send + Sync + 'static;
// Required method
fn asset_eq(old: &Self::Asset, new: &Self::Asset) -> bool;
// Provided method
fn durability(&self) -> DurabilityLevel { ... }
}Expand description
Trait for asset keys that map to loadable assets.
Asset keys identify external resources (files, URLs, etc.) and define the type of asset they load. Assets are leaf nodes in the dependency graph - they have no dependencies but can be depended upon by queries.
§Example
ⓘ
use query_flow::{asset_key, AssetKey, DurabilityLevel};
#[asset_key(asset = String)]
pub struct ConfigFile(pub PathBuf);
#[asset_key(asset = String, durability = constant)]
pub struct BundledFile(pub PathBuf);
// Or manually:
pub struct TextureId(pub u32);
impl AssetKey for TextureId {
type Asset = ImageData;
fn asset_eq(old: &Self::Asset, new: &Self::Asset) -> bool {
old.bytes == new.bytes
}
fn durability(&self) -> DurabilityLevel {
DurabilityLevel::Constant
}
}Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn durability(&self) -> DurabilityLevel
fn durability(&self) -> DurabilityLevel
Durability level for this asset type.
Higher values indicate the asset changes less frequently.
Default: Volatile (changes frequently).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.