Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 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,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,
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 14 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,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.
Expand Down