Loader

Struct Loader 

Source
pub struct Loader { /* private fields */ }
Expand description

Loads and tracks lifetimes of asset data.

Implementations§

Source§

impl Loader

Source

pub fn new(io: Box<dyn LoaderIO>) -> Loader

Source

pub fn new_with_handle_allocator( io: Box<dyn LoaderIO>, handle_allocator: Arc<dyn HandleAllocator>, ) -> Loader

Source

pub fn with_serde_context<R>( &self, tx: &Sender<RefOp>, f: impl FnMut() -> R, ) -> R

Source

pub fn get_load(&self, id: AssetUuid) -> Option<LoadHandle>

Returns the load handle for the asset with the given UUID, if present.

This will only return Some(..) if there has been a previous call to Loader::add_ref.

§Parameters
  • id: UUID of the asset.
Source

pub fn get_load_info(&self, load: LoadHandle) -> Option<LoadInfo>

Returns information about the load of an asset.

Note: The information is true at the time the LoadInfo is retrieved. The actual number of references may change.

§Parameters
  • load_handle: ID allocated by Loader to track loading of the asset.
Source

pub fn get_active_loads(&self) -> Vec<LoadHandle>

Returns handles to all active asset loads.

Source

pub fn get_load_status(&self, load: LoadHandle) -> LoadStatus

Returns the asset load status.

§Parameters
  • load: ID allocated by Loader to track loading of the asset.
Source

pub fn add_ref_handle(&self, handle: LoadHandle)

Source

pub fn add_ref<U: Into<AssetUuid>>(&self, id: U) -> LoadHandle

Adds a reference to an asset and returns its LoadHandle.

If the asset is already loaded, this returns the existing LoadHandle. If it is not loaded, this allocates a new LoadHandle and returns that.

§Parameters
  • id: UUID of the asset.
Source

pub fn add_ref_indirect(&self, id: IndirectIdentifier) -> LoadHandle

Adds a reference to an indirect id and returns its LoadHandle with LoadHandle::is_indirect set to true.

§Parameters
  • id: IndirectIdentifier for the load.
Source

pub fn get_asset_type(&self, load: LoadHandle) -> Option<AssetTypeId>

Returns the AssetTypeId for the currently loaded asset of the provided load handle.

§Parameters
  • load: ID allocated by Loader to track loading of the asset.
Source

pub fn remove_ref(&self, load: LoadHandle)

Removes a reference to an asset.

§Parameters
  • load_handle: ID allocated by Loader to track loading of the asset.
Source

pub fn process( &mut self, asset_storage: &dyn AssetStorage, resolver: &dyn IndirectionResolver, ) -> Result<()>

Processes pending load operations.

Load operations include:

§Parameters
  • asset_storage: Storage for all assets of all asset types.
Source

pub fn indirection_table(&self) -> IndirectionTable

Returns a reference to the loader’s IndirectionTable.

When a user fetches an asset by LoadHandle, implementors of AssetStorage should resolve LoadHandles where LoadHandle::is_indirect returns true by using IndirectionTable::resolve. IndirectionTable is Send + Sync + Clone so that it can be retrieved once at startup, then stored in implementors of AssetStorage.

Source

pub fn invalidate_assets(&self, assets: &[AssetUuid])

Invalidates the data & metadata of the provided asset IDs.

This causes the asset data to be reloaded.

Source

pub fn invalidate_paths(&self, paths: &[PathBuf])

Invalidates indirect identifiers that may match the provided paths.

This may cause indirect handles to resolve to new assets.

Auto Trait Implementations§

§

impl Freeze for Loader

§

impl !RefUnwindSafe for Loader

§

impl Send for Loader

§

impl Sync for Loader

§

impl Unpin for Loader

§

impl !UnwindSafe for Loader

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.