Struct bevy::asset::ReflectHandle
source · pub struct ReflectHandle { /* private fields */ }
Expand description
Reflect type data struct relating a Handle<T>
back to the T
asset type.
Say you want to look up the asset values of a list of handles when you have access to their &dyn Reflect
form.
Assets can be looked up in the world using ReflectAsset
, but how do you determine which ReflectAsset
to use when
only looking at the handle? ReflectHandle
is stored in the type registry on each Handle<T>
type, so you can use ReflectHandle::asset_type_id
to look up
the ReflectAsset
type data on the corresponding T
asset type:
use bevy_asset::{ReflectHandle, ReflectAsset};
let handles: Vec<&dyn Reflect> = unimplemented!();
for handle in handles {
let reflect_handle = type_registry.get_type_data::<ReflectHandle>(handle.type_id()).unwrap();
let reflect_asset = type_registry.get_type_data::<ReflectAsset>(reflect_handle.asset_type_id()).unwrap();
let handle = reflect_handle.downcast_handle_untyped(handle.as_any()).unwrap();
let value = reflect_asset.get(world, handle).unwrap();
println!("{value:?}");
}
Implementations§
source§impl ReflectHandle
impl ReflectHandle
sourcepub fn asset_type_id(&self) -> TypeId
pub fn asset_type_id(&self) -> TypeId
The TypeId
of the asset
sourcepub fn downcast_handle_untyped(
&self,
handle: &(dyn Any + 'static)
) -> Option<UntypedHandle>
pub fn downcast_handle_untyped( &self, handle: &(dyn Any + 'static) ) -> Option<UntypedHandle>
A way to go from a Handle<T>
in a dyn Any
to a UntypedHandle
sourcepub fn typed(&self, handle: UntypedHandle) -> Box<dyn Reflect>
pub fn typed(&self, handle: UntypedHandle) -> Box<dyn Reflect>
A way to go from a UntypedHandle
to a Handle<T>
in a Box<dyn Reflect>
.
Equivalent of UntypedHandle::typed
.
Trait Implementations§
source§impl Clone for ReflectHandle
impl Clone for ReflectHandle
source§fn clone(&self) -> ReflectHandle
fn clone(&self) -> ReflectHandle
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<A> FromType<Handle<A>> for ReflectHandlewhere
A: Asset,
impl<A> FromType<Handle<A>> for ReflectHandlewhere
A: Asset,
fn from_type() -> ReflectHandle
Auto Trait Implementations§
impl RefUnwindSafe for ReflectHandle
impl Send for ReflectHandle
impl Sync for ReflectHandle
impl Unpin for ReflectHandle
impl UnwindSafe for ReflectHandle
Blanket Implementations§
source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
Return the
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.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
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>
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>
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)
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)
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.