Skip to content

Commit 902f42b

Browse files
committed
Impl AsRef+AsMut for Res, ResMut, and Mut
1 parent e3435e5 commit 902f42b

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

crates/bevy_ecs/src/system/system_param.rs

+21
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ impl<'w, T: Component> Deref for Res<'w, T> {
207207
}
208208
}
209209

210+
impl<'w, T: Component> AsRef<T> for Res<'w, T> {
211+
#[inline]
212+
fn as_ref(&self) -> &T {
213+
&*self
214+
}
215+
}
216+
210217
/// The [`SystemParamState`] of [`Res`].
211218
pub struct ResState<T> {
212219
component_id: ComponentId,
@@ -367,6 +374,20 @@ impl<'w, T: Component> DerefMut for ResMut<'w, T> {
367374
}
368375
}
369376

377+
impl<'w, T: Component> AsRef<T> for ResMut<'w, T> {
378+
#[inline]
379+
fn as_ref(&self) -> &T {
380+
&*self
381+
}
382+
}
383+
384+
impl<'w, T: Component> AsMut<T> for ResMut<'w, T> {
385+
#[inline]
386+
fn as_mut(&mut self) -> &mut T {
387+
self.deref_mut()
388+
}
389+
}
390+
370391
/// The [`SystemParamState`] of [`ResMut`].
371392
pub struct ResMutState<T> {
372393
component_id: ComponentId,

crates/bevy_ecs/src/world/pointer.rs

+14
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ impl<'a, T: core::fmt::Debug> core::fmt::Debug for Mut<'a, T> {
3939
}
4040
}
4141

42+
impl<'w, T> AsRef<T> for Mut<'w, T> {
43+
#[inline]
44+
fn as_ref(&self) -> &T {
45+
&*self
46+
}
47+
}
48+
49+
impl<'w, T> AsMut<T> for Mut<'w, T> {
50+
#[inline]
51+
fn as_mut(&mut self) -> &mut T {
52+
self.deref_mut()
53+
}
54+
}
55+
4256
impl<'w, T> Mut<'w, T> {
4357
/// Returns true if (and only if) this component been added since the last execution of this
4458
/// system.

0 commit comments

Comments
 (0)