bevy_asset

Struct NestedLoader

Source
pub struct NestedLoader<'ctx, 'builder, T, M> { /* private fields */ }
Expand description

A builder for loading nested assets inside a LoadContext.

§Loader state

The type parameters T and M determine how this will load assets:

  • T: the typing of this loader. How do we know what type of asset to load?

    See StaticTyped (the default), DynamicTyped, and UnknownTyped.

  • M: the load mode. Do we want to load this asset right now (in which case you will have to await the operation), or do we just want a Handle, and leave the actual asset loading to later?

    See Deferred (the default) and Immediate.

When configuring this builder, you can freely switch between these modes via functions like deferred and immediate.

§Typing

To inform the loader of what type of asset to load:

§Load mode

To inform the loader how you want to load the asset:

  • in Deferred: when you request to load the asset, you get a Handle for it, but the actual loading won’t be completed until later.

    Use this if you only need a Handle or UntypedHandle.

  • in Immediate: the load request will load the asset right then and there, waiting until the asset is fully loaded and giving you access to it.

    Note that this requires you to await a future, so you must be in an async context to use direct loading. In an asset loader, you will be in an async context.

    Use this if you need the value of another asset in order to load the current asset. For example, if you are deriving a new asset from the referenced asset, or you are building a collection of assets. This will add the path of the asset as a “load dependency”.

    If the current loader is used in a Process “asset preprocessor”, such as a LoadTransformAndSave preprocessor, changing a “load dependency” will result in re-processing of the asset.

§Load kickoff

If the current context is a normal AssetServer::load, an actual asset load will be kicked off immediately, which ensures the load happens as soon as possible. “Normal loads” kicked from within a normal Bevy App will generally configure the context to kick off loads immediately.

If the current context is configured to not load dependencies automatically (ex: AssetProcessor), a load will not be kicked off automatically. It is then the calling context’s responsibility to begin a load if necessary.

§Lifetimes

  • ctx: the lifetime of the associated AssetServer reference
  • builder: the lifetime of the temporary builder structs

Implementations§

Source§

impl<'ctx, 'builder, T: Typing, M: Mode> NestedLoader<'ctx, 'builder, T, M>

Source

pub fn with_settings<S: Settings>( self, settings: impl Fn(&mut S) + Send + Sync + 'static, ) -> Self

Configure the settings used to load the asset.

If the settings type S does not match the settings expected by A’s asset loader, an error will be printed to the log and the asset load will fail.

Source

pub fn with_static_type(self) -> NestedLoader<'ctx, 'builder, StaticTyped, M>

When loading, you must pass in the asset type as a type parameter statically.

If you don’t know the type statically (at compile time), consider with_dynamic_type or with_unknown_type.

Source

pub fn with_dynamic_type( self, asset_type_id: TypeId, ) -> NestedLoader<'ctx, 'builder, DynamicTyped, M>

When loading, the loader will attempt to load an asset with the given TypeId.

Source

pub fn with_unknown_type(self) -> NestedLoader<'ctx, 'builder, UnknownTyped, M>

When loading, we will infer what type of asset to load from metadata.

Source

pub fn deferred(self) -> NestedLoader<'ctx, 'builder, T, Deferred>

When loading, create only asset handles, rather than returning the actual asset.

Source

pub fn immediate<'c>( self, ) -> NestedLoader<'ctx, 'builder, T, Immediate<'builder, 'c>>

The load call itself will load an asset, rather than scheduling the loading to happen later.

This gives you access to the loaded asset, but requires you to be in an async context, and be able to await the resulting future.

Source§

impl NestedLoader<'_, '_, StaticTyped, Deferred>

Source

pub fn load<'c, A: Asset>(self, path: impl Into<AssetPath<'c>>) -> Handle<A>

Retrieves a handle for the asset at the given path and adds that path as a dependency of this asset.

This requires you to know the type of asset statically.

Source§

impl NestedLoader<'_, '_, DynamicTyped, Deferred>

Source

pub fn load<'p>(self, path: impl Into<AssetPath<'p>>) -> UntypedHandle

Retrieves a handle for the asset at the given path and adds that path as a dependency of this asset.

This requires you to pass in the asset type ID into with_dynamic_type.

Source§

impl NestedLoader<'_, '_, UnknownTyped, Deferred>

Source

pub fn load<'p>( self, path: impl Into<AssetPath<'p>>, ) -> Handle<LoadedUntypedAsset>

Retrieves a handle for the asset at the given path and adds that path as a dependency of this asset.

This will infer the asset type from metadata.

Source§

impl<'builder, 'reader, T> NestedLoader<'_, '_, T, Immediate<'builder, 'reader>>

Source

pub fn with_reader(self, reader: &'builder mut (dyn Reader + 'reader)) -> Self

Specify the reader to use to read the asset data.

Source§

impl NestedLoader<'_, '_, StaticTyped, Immediate<'_, '_>>

Source

pub async fn load<'p, A: Asset>( self, path: impl Into<AssetPath<'p>>, ) -> Result<LoadedAsset<A>, LoadDirectError>

Attempts to load the asset at the given path immediately.

This requires you to know the type of asset statically.

Source§

impl NestedLoader<'_, '_, DynamicTyped, Immediate<'_, '_>>

Source

pub async fn load<'p>( self, path: impl Into<AssetPath<'p>>, ) -> Result<ErasedLoadedAsset, LoadDirectError>

Attempts to load the asset at the given path immediately.

This requires you to pass in the asset type ID into with_dynamic_type.

Source§

impl NestedLoader<'_, '_, UnknownTyped, Immediate<'_, '_>>

Source

pub async fn load<'p>( self, path: impl Into<AssetPath<'p>>, ) -> Result<ErasedLoadedAsset, LoadDirectError>

Attempts to load the asset at the given path immediately.

This will infer the asset type from metadata.

Auto Trait Implementations§

§

impl<'ctx, 'builder, T, M> Freeze for NestedLoader<'ctx, 'builder, T, M>
where T: Freeze, M: Freeze,

§

impl<'ctx, 'builder, T, M> !RefUnwindSafe for NestedLoader<'ctx, 'builder, T, M>

§

impl<'ctx, 'builder, T, M> Send for NestedLoader<'ctx, 'builder, T, M>
where T: Send, M: Send,

§

impl<'ctx, 'builder, T, M> Sync for NestedLoader<'ctx, 'builder, T, M>
where T: Sync, M: Sync,

§

impl<'ctx, 'builder, T, M> Unpin for NestedLoader<'ctx, 'builder, T, M>
where T: Unpin, M: Unpin,

§

impl<'ctx, 'builder, T, M> !UnwindSafe for NestedLoader<'ctx, 'builder, T, M>

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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> ConditionalSend for T
where T: Send,

Source§

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