mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Impl AsRef+AsMut for Res, ResMut, and Mut (#2189)
This can save users from having to type `&*X` all the time at the cost of some complexity in the type signature. For instance, this allows me to accommodate @jakobhellermann's suggestion in #1799 without requiring users to type `&*windows` 99% of the time.
This commit is contained in:
parent
177f2fbf9a
commit
cb98d31b27
2 changed files with 35 additions and 0 deletions
|
@ -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,
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue