Skip to content

Commit 50c74e5

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

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

crates/bevy_ecs/src/system/system_param.rs

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

210+
impl<'w, T: Component> AsRef<T> for Res<'w, T> {
211+
fn as_ref(&self) -> &T {
212+
&*self
213+
}
214+
}
215+
210216
/// The [`SystemParamState`] of [`Res`].
211217
pub struct ResState<T> {
212218
component_id: ComponentId,
@@ -367,6 +373,18 @@ impl<'w, T: Component> DerefMut for ResMut<'w, T> {
367373
}
368374
}
369375

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

crates/bevy_ecs/src/world/pointer.rs

+12
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ 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+
fn as_ref(&self) -> &T {
44+
&*self
45+
}
46+
}
47+
48+
impl<'w, T> AsMut<T> for Mut<'w, T> {
49+
fn as_mut(&mut self) -> &mut T {
50+
self.deref_mut()
51+
}
52+
}
53+
4254
impl<'w, T> Mut<'w, T> {
4355
/// Returns true if (and only if) this component been added since the last execution of this
4456
/// system.

0 commit comments

Comments
 (0)