Skip to main content

AssetInspector

Struct AssetInspector 

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

Source

pub fn new(database: &'a AssetDatabase, handle: AssetHandle) -> Self

Creates a new AssetInspector instance for the given asset handle.

§Arguments
  • database - A reference to the AssetDatabase containing the asset.
  • handle - The AssetHandle representing the asset to inspect.
§Returns

A new AssetInspector instance.

Source

pub fn new_raw(storage: &'a World, entity: Entity) -> Self

Creates a new AssetInspector instance for the given asset entity.

§Arguments
  • storage - A reference to the World containing the asset entity.
  • entity - The Entity representing the asset to inspect.
§Returns

A new AssetInspector instance.

Source

pub fn storage(&self) -> &'a World

Returns a reference to the underlying storage.

Source

pub fn handle(&self) -> AssetHandle

Returns the assigned asset handle.

Source

pub fn path(&self) -> Result<AssetPathStatic, Box<dyn Error>>

Returns the asset path associated with the asset.

Source

pub fn access_checked<Fetch: TypedLookupFetch<'a, true>>( &self, ) -> Option<Fetch::Value>

Tries to access typed data for this asset.

Source

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

pub fn dependencies(&'a self) -> impl Iterator<Item = Self> + 'a

Returns an iterator over asset dependencies.

Source

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> 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> Finalize for T

Source§

unsafe fn finalize_raw(data: *mut ())

Safety Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Component for T
where T: Send + Sync + 'static,