Skip to content

Commit

Permalink
Impl AsRef+AsMut for Res, ResMut, and Mut
Browse files Browse the repository at this point in the history
  • Loading branch information
anchpop committed May 17, 2021
1 parent e3435e5 commit 50c74e5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crates/bevy_ecs/src/system/system_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ impl<'w, T: Component> Deref for Res<'w, T> {
}
}

impl<'w, T: Component> AsRef<T> for Res<'w, T> {
fn as_ref(&self) -> &T {
&*self
}
}

/// The [`SystemParamState`] of [`Res`].
pub struct ResState<T> {
component_id: ComponentId,
Expand Down Expand Up @@ -367,6 +373,18 @@ impl<'w, T: Component> DerefMut for ResMut<'w, T> {
}
}

impl<'w, T: Component> AsRef<T> for ResMut<'w, T> {
fn as_ref(&self) -> &T {
&*self
}
}

impl<'w, T: Component> AsMut<T> for ResMut<'w, T> {
fn as_mut(&mut self) -> &mut T {
self.deref_mut()
}
}

/// The [`SystemParamState`] of [`ResMut`].
pub struct ResMutState<T> {
component_id: ComponentId,
Expand Down
12 changes: 12 additions & 0 deletions crates/bevy_ecs/src/world/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ impl<'a, T: core::fmt::Debug> core::fmt::Debug for Mut<'a, T> {
}
}

impl<'w, T> AsRef<T> for Mut<'w, T> {
fn as_ref(&self) -> &T {
&*self
}
}

impl<'w, T> AsMut<T> for Mut<'w, T> {
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.
Expand Down

0 comments on commit 50c74e5

Please sign in to comment.