pub struct AssetInspector<'a> { /* private fields */ }Expand description
The AssetInspector struct provides a way to access asset path, its
components, as well as dependencies.
Implementations§
Source§impl<'a> AssetInspector<'a>
impl<'a> AssetInspector<'a>
Sourcepub fn new(database: &'a AssetDatabase, handle: AssetHandle) -> Self
pub fn new(database: &'a AssetDatabase, handle: AssetHandle) -> Self
Sourcepub fn handle(&self) -> AssetHandle
pub fn handle(&self) -> AssetHandle
Returns the assigned asset handle.
Sourcepub fn path(&self) -> Result<AssetPathStatic, Box<dyn Error>>
pub fn path(&self) -> Result<AssetPathStatic, Box<dyn Error>>
Returns the asset path associated with the asset.
Sourcepub fn access_checked<Fetch: TypedLookupFetch<'a, true>>(
&self,
) -> Option<Fetch::Value>
pub fn access_checked<Fetch: TypedLookupFetch<'a, true>>( &self, ) -> Option<Fetch::Value>
Tries to access typed data for this asset.
Sourcepub fn access<Fetch: TypedLookupFetch<'a, true>>(&self) -> Fetch::Value
pub fn access<Fetch: TypedLookupFetch<'a, true>>(&self) -> Fetch::Value
Accesses typed data for this asset or panics if it cannot.
Examples found in repository?
examples/22_store_custom_asset.rs (line 30)
17fn main() -> Result<(), Box<dyn Error>> {
18 /* ANCHOR: main */
19 let mut database = AssetDatabase::default()
20 .with_protocol(BundleAssetProtocol::new(
21 "json",
22 (
23 |bytes: Vec<u8>| {
24 let asset = serde_json::from_slice::<Person>(&bytes)?;
25 Ok((asset,).into())
26 },
27 // Additionally to decoding asset we can also encode it back to bytes.
28 // This is useful for saving assets to storage.
29 |inspector: AssetInspector| {
30 let asset = inspector.access::<&Person>();
31 let bytes = serde_json::to_vec(asset)?;
32 Ok(bytes.into())
33 },
34 ),
35 ))
36 .with_fetch(FileAssetFetch::default().with_root("resources"))
37 .with_store(FileAssetStore::default().with_root("resources"));
38
39 let _ = std::fs::remove_file("./resources/saved.json");
40
41 let before = database.spawn(
42 "json://saved.json",
43 (Person {
44 name: "Alice".to_owned(),
45 age: 42,
46 },),
47 )?;
48 println!("Before: {:?}", before.access::<&Person>(&database));
49 before.store(&mut database)?;
50
51 while database.is_busy() {
52 database.maintain()?;
53 }
54
55 before.delete(&mut database);
56 assert!(!before.does_exists(&database));
57
58 // Load the asset from storage, we get previously saved asset content.
59 let after = database.ensure("json://saved.json")?;
60 println!("After: {:?}", after.access::<&Person>(&database));
61 /* ANCHOR_END: main */
62
63 Ok(())
64}Sourcepub fn dependencies(&'a self) -> impl Iterator<Item = Self> + 'a
pub fn dependencies(&'a self) -> impl Iterator<Item = Self> + 'a
Returns an iterator over asset dependencies.
Sourcepub fn traverse_dependencies(&'a self) -> impl Iterator<Item = Self> + 'a
pub fn traverse_dependencies(&'a self) -> impl Iterator<Item = Self> + 'a
Recursively iterates through all assigned asset dependencies.
Auto Trait Implementations§
impl<'a> Freeze for AssetInspector<'a>
impl<'a> RefUnwindSafe for AssetInspector<'a>
impl<'a> Send for AssetInspector<'a>
impl<'a> Sync for AssetInspector<'a>
impl<'a> Unpin for AssetInspector<'a>
impl<'a> UnwindSafe for AssetInspector<'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