Struct bevy::asset::ReflectHandle
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§
§impl ReflectHandle
impl ReflectHandle
pub fn type_uuid(&self) -> Uuid
pub fn type_uuid(&self) -> Uuid
The bevy_reflect::TypeUuid of the asset
pub fn asset_type_id(&self) -> TypeId
pub fn asset_type_id(&self) -> TypeId
The TypeId of the asset
pub fn downcast_handle_untyped(
&self,
handle: &(dyn Any + 'static)
) -> Option<HandleUntyped>
pub fn downcast_handle_untyped( &self, handle: &(dyn Any + 'static) ) -> Option<HandleUntyped>
A way to go from a Handle<T> in a dyn Any to a HandleUntyped
pub fn typed(&self, handle: HandleUntyped) -> Box<dyn Reflect + 'static, Global>
pub fn typed(&self, handle: HandleUntyped) -> Box<dyn Reflect + 'static, Global>
A way to go from a HandleUntyped to a Handle<T> in a Box<dyn Reflect>.
Equivalent of HandleUntyped::typed.
Trait Implementations§
§impl Clone for ReflectHandle
impl Clone for ReflectHandle
§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 more§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§
§impl<T, U> AsBindGroupShaderType<U> for Twhere
U: ShaderType,
&'a T: for<'a> Into<U>,
impl<T, U> AsBindGroupShaderType<U> for Twhere U: ShaderType, &'a T: for<'a> Into<U>,
§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.§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
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.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§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.§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.