diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index 5dce8e4b2e477..fda3684e6e056 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -207,6 +207,13 @@ impl<'w, T: Component> Deref for Res<'w, T> { } } +impl<'w, T: Component> AsRef<T> for Res<'w, T> { + #[inline] + fn as_ref(&self) -> &T { + self.deref() + } +} + /// The [`SystemParamState`] of [`Res`]. pub struct ResState<T> { component_id: ComponentId, @@ -367,6 +374,20 @@ impl<'w, T: Component> DerefMut for ResMut<'w, T> { } } +impl<'w, T: Component> AsRef<T> for ResMut<'w, T> { + #[inline] + fn as_ref(&self) -> &T { + self.deref() + } +} + +impl<'w, T: Component> AsMut<T> for ResMut<'w, T> { + #[inline] + fn as_mut(&mut self) -> &mut T { + self.deref_mut() + } +} + /// The [`SystemParamState`] of [`ResMut`]. pub struct ResMutState<T> { component_id: ComponentId, diff --git a/crates/bevy_ecs/src/world/pointer.rs b/crates/bevy_ecs/src/world/pointer.rs index 695b2eb75096d..68d3f5d753715 100644 --- a/crates/bevy_ecs/src/world/pointer.rs +++ b/crates/bevy_ecs/src/world/pointer.rs @@ -39,6 +39,20 @@ impl<'a, T: core::fmt::Debug> core::fmt::Debug for Mut<'a, T> { } } +impl<'w, T> AsRef<T> for Mut<'w, T> { + #[inline] + fn as_ref(&self) -> &T { + self.deref() + } +} + +impl<'w, T> AsMut<T> for Mut<'w, T> { + #[inline] + fn as_mut(&mut self) -> &mut T { + self.deref_mut() + } +} + impl<'w, T> Mut<'w, T> { /// Returns true if (and only if) this component been added since the last execution of this /// system.