Struct bevy_internal::asset::ReflectAsset
source · pub struct ReflectAsset { /* private fields */ }
Expand description
Type data for the TypeRegistry
used to operate on reflected Asset
s.
This type provides similar methods to Assets<T>
like get
,
add
and remove
, but can be used in situations where you don’t know which asset type T
you want
until runtime.
ReflectAsset
can be obtained via TypeRegistration::data
if the asset was registered using register_asset_reflect
.
Implementations§
source§impl ReflectAsset
impl ReflectAsset
sourcepub fn handle_type_id(&self) -> TypeId
pub fn handle_type_id(&self) -> TypeId
sourcepub fn assets_resource_type_id(&self) -> TypeId
pub fn assets_resource_type_id(&self) -> TypeId
sourcepub fn get<'w>(
&self,
world: &'w World,
handle: UntypedHandle
) -> Option<&'w (dyn Reflect + 'static)>
pub fn get<'w>( &self, world: &'w World, handle: UntypedHandle ) -> Option<&'w (dyn Reflect + 'static)>
Equivalent of Assets::get
sourcepub fn get_mut<'w>(
&self,
world: &'w mut World,
handle: UntypedHandle
) -> Option<&'w mut (dyn Reflect + 'static)>
pub fn get_mut<'w>( &self, world: &'w mut World, handle: UntypedHandle ) -> Option<&'w mut (dyn Reflect + 'static)>
Equivalent of Assets::get_mut
sourcepub unsafe fn get_unchecked_mut<'w>(
&self,
world: UnsafeWorldCell<'w>,
handle: UntypedHandle
) -> Option<&'w mut (dyn Reflect + 'static)>
pub unsafe fn get_unchecked_mut<'w>( &self, world: UnsafeWorldCell<'w>, handle: UntypedHandle ) -> Option<&'w mut (dyn Reflect + 'static)>
Equivalent of Assets::get_mut
, but works with an UnsafeWorldCell
.
Only use this method when you have ensured that you are the only one with access to the Assets
resource of the asset type.
Furthermore, this does not allow you to have look up two distinct handles,
you can only have at most one alive at the same time.
This means that this is not allowed:
let unsafe_world_cell = world.as_unsafe_world_cell();
let a = unsafe { reflect_asset.get_unchecked_mut(unsafe_world_cell, handle_1).unwrap() };
let b = unsafe { reflect_asset.get_unchecked_mut(unsafe_world_cell, handle_2).unwrap() };
// ^ not allowed, two mutable references through the same asset resource, even though the
// handles are distinct
println!("a = {a:?}, b = {b:?}");
Safety
This method does not prevent you from having two mutable pointers to the same data, violating Rust’s aliasing rules. To avoid this:
- Only call this method if you know that the
UnsafeWorldCell
may be used to access the correspondingAssets<T>
- Don’t call this method more than once in the same scope.
sourcepub fn add(
&self,
world: &mut World,
value: &(dyn Reflect + 'static)
) -> UntypedHandle
pub fn add( &self, world: &mut World, value: &(dyn Reflect + 'static) ) -> UntypedHandle
Equivalent of Assets::add
sourcepub fn insert(
&self,
world: &mut World,
handle: UntypedHandle,
value: &(dyn Reflect + 'static)
)
pub fn insert( &self, world: &mut World, handle: UntypedHandle, value: &(dyn Reflect + 'static) )
Equivalent of Assets::insert
sourcepub fn remove(
&self,
world: &mut World,
handle: UntypedHandle
) -> Option<Box<dyn Reflect>>
pub fn remove( &self, world: &mut World, handle: UntypedHandle ) -> Option<Box<dyn Reflect>>
Equivalent of Assets::remove
sourcepub fn len(&self, world: &World) -> usize
pub fn len(&self, world: &World) -> usize
Equivalent of Assets::len
sourcepub fn is_empty(&self, world: &World) -> bool
pub fn is_empty(&self, world: &World) -> bool
Equivalent of Assets::is_empty
sourcepub fn ids<'w>(
&self,
world: &'w World
) -> impl Iterator<Item = UntypedAssetId> + 'w
pub fn ids<'w>( &self, world: &'w World ) -> impl Iterator<Item = UntypedAssetId> + 'w
Equivalent of Assets::ids
Trait Implementations§
source§impl Clone for ReflectAsset
impl Clone for ReflectAsset
source§fn clone(&self) -> ReflectAsset
fn clone(&self) -> ReflectAsset
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<A> FromType<A> for ReflectAssetwhere
A: Asset + FromReflect,
impl<A> FromType<A> for ReflectAssetwhere
A: Asset + FromReflect,
fn from_type() -> ReflectAsset
Auto Trait Implementations§
impl RefUnwindSafe for ReflectAsset
impl Send for ReflectAsset
impl Sync for ReflectAsset
impl Unpin for ReflectAsset
impl UnwindSafe for ReflectAsset
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
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
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.