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
, andUnknownTyped
. -
M
: the load mode. Do we want to load this asset right now (in which case you will have toawait
the operation), or do we just want aHandle
, and leave the actual asset loading to later?
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:
-
in
StaticTyped
: statically providing a type parameterA: Asset
toload
.This is the simplest way to get a
Handle<A>
to the loaded asset, as long as you know the type ofA
at compile time. -
in
DynamicTyped
: providing theTypeId
of the asset at runtime.If you know the type ID of the asset at runtime, but not at compile time, use
with_dynamic_type
followed byload
to start loading an asset of that type. This lets you get anUntypedHandle
(viaDeferred
), or aErasedLoadedAsset
(viaImmediate
). -
in
UnknownTyped
: loading either a type-erased version of the asset (ErasedLoadedAsset
), or a handle to a handle of the actual asset (LoadedUntypedAsset
).If you have no idea what type of asset you will be loading (not even at runtime with a
TypeId
), use this.
§Load mode
To inform the loader how you want to load the asset:
-
in
Deferred
: when you request to load the asset, you get aHandle
for it, but the actual loading won’t be completed until later.Use this if you only need a
Handle
orUntypedHandle
. -
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 aLoadTransformAndSave
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 associatedAssetServer
referencebuilder
: the lifetime of the temporary builder structs
Implementations§
Source§impl<'ctx, 'builder, T: Typing, M: Mode> NestedLoader<'ctx, 'builder, T, M>
impl<'ctx, 'builder, T: Typing, M: Mode> NestedLoader<'ctx, 'builder, T, M>
Sourcepub fn with_settings<S: Settings>(
self,
settings: impl Fn(&mut S) + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn with_static_type(self) -> NestedLoader<'ctx, 'builder, StaticTyped, M>
pub fn with_static_type(self) -> NestedLoader<'ctx, 'builder, StaticTyped, M>
When load
ing, 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
.
Sourcepub fn with_dynamic_type(
self,
asset_type_id: TypeId,
) -> NestedLoader<'ctx, 'builder, DynamicTyped, M>
pub fn with_dynamic_type( self, asset_type_id: TypeId, ) -> NestedLoader<'ctx, 'builder, DynamicTyped, M>
Sourcepub fn with_unknown_type(self) -> NestedLoader<'ctx, 'builder, UnknownTyped, M>
pub fn with_unknown_type(self) -> NestedLoader<'ctx, 'builder, UnknownTyped, M>
When load
ing, we will infer what type of asset to load from
metadata.
Sourcepub fn deferred(self) -> NestedLoader<'ctx, 'builder, T, Deferred>
pub fn deferred(self) -> NestedLoader<'ctx, 'builder, T, Deferred>
When load
ing, create only asset handles, rather than returning the
actual asset.
Sourcepub fn immediate<'c>(
self,
) -> NestedLoader<'ctx, 'builder, T, Immediate<'builder, 'c>>
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>
impl NestedLoader<'_, '_, StaticTyped, Deferred>
Sourcepub fn load<'c, A: Asset>(self, path: impl Into<AssetPath<'c>>) -> Handle<A>
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.
- If you have runtime info for what type of asset you’re loading (e.g. a
TypeId
), usewith_dynamic_type
. - If you do not know at all what type of asset you’re loading, use
with_unknown_type
.
Source§impl NestedLoader<'_, '_, DynamicTyped, Deferred>
impl NestedLoader<'_, '_, DynamicTyped, Deferred>
Sourcepub fn load<'p>(self, path: impl Into<AssetPath<'p>>) -> UntypedHandle
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>
impl NestedLoader<'_, '_, UnknownTyped, Deferred>
Source§impl<'builder, 'reader, T> NestedLoader<'_, '_, T, Immediate<'builder, 'reader>>
impl<'builder, 'reader, T> NestedLoader<'_, '_, T, Immediate<'builder, 'reader>>
Sourcepub fn with_reader(self, reader: &'builder mut (dyn Reader + 'reader)) -> Self
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<'_, '_>>
impl NestedLoader<'_, '_, StaticTyped, Immediate<'_, '_>>
Sourcepub async fn load<'p, A: Asset>(
self,
path: impl Into<AssetPath<'p>>,
) -> Result<LoadedAsset<A>, LoadDirectError>
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.
- If you have runtime info for what type of asset you’re loading (e.g. a
TypeId
), usewith_dynamic_type
. - If you do not know at all what type of asset you’re loading, use
with_unknown_type
.
Source§impl NestedLoader<'_, '_, DynamicTyped, Immediate<'_, '_>>
impl NestedLoader<'_, '_, DynamicTyped, Immediate<'_, '_>>
Sourcepub async fn load<'p>(
self,
path: impl Into<AssetPath<'p>>,
) -> Result<ErasedLoadedAsset, LoadDirectError>
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<'_, '_>>
impl NestedLoader<'_, '_, UnknownTyped, Immediate<'_, '_>>
Sourcepub async fn load<'p>(
self,
path: impl Into<AssetPath<'p>>,
) -> Result<ErasedLoadedAsset, LoadDirectError>
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>
impl<'ctx, 'builder, T, M> !RefUnwindSafe for NestedLoader<'ctx, 'builder, T, M>
impl<'ctx, 'builder, T, M> Send for NestedLoader<'ctx, 'builder, T, M>
impl<'ctx, 'builder, T, M> Sync for NestedLoader<'ctx, 'builder, T, M>
impl<'ctx, 'builder, T, M> Unpin for NestedLoader<'ctx, 'builder, T, M>
impl<'ctx, 'builder, T, M> !UnwindSafe for NestedLoader<'ctx, 'builder, T, M>
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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