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>
pub fn get<'w>( &self, world: &'w World, handle: UntypedHandle, ) -> Option<&'w dyn Reflect>
Equivalent of Assets::get
Sourcepub fn get_mut<'w>(
&self,
world: &'w mut World,
handle: UntypedHandle,
) -> Option<&'w mut dyn Reflect>
pub fn get_mut<'w>( &self, world: &'w mut World, handle: UntypedHandle, ) -> Option<&'w mut dyn Reflect>
Equivalent of Assets::get_mut
Sourcepub unsafe fn get_unchecked_mut<'w>(
&self,
world: UnsafeWorldCell<'w>,
handle: UntypedHandle,
) -> Option<&'w mut dyn Reflect>
pub unsafe fn get_unchecked_mut<'w>( &self, world: UnsafeWorldCell<'w>, handle: UntypedHandle, ) -> Option<&'w mut dyn Reflect>
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 PartialReflect,
) -> UntypedHandle
pub fn add( &self, world: &mut World, value: &dyn PartialReflect, ) -> UntypedHandle
Equivalent of Assets::add
Sourcepub fn insert(
&self,
world: &mut World,
handle: UntypedHandle,
value: &dyn PartialReflect,
)
pub fn insert( &self, world: &mut World, handle: UntypedHandle, value: &dyn PartialReflect, )
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: Asset + FromReflect> FromType<A> for ReflectAsset
impl<A: Asset + FromReflect> FromType<A> for ReflectAsset
Auto Trait Implementations§
impl Freeze for ReflectAsset
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> 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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