From implementations

This commit is contained in:
rosefarts 2024-09-17 15:50:29 +02:00
parent b45d83ebda
commit 62081c66cd

View file

@ -587,6 +587,30 @@ impl<'w, T: Resource> From<ResMut<'w, T>> for Res<'w, T> {
}
}
impl<'w, T: Resource> From<Ref<'w, T>> for Res<'w, T> {
fn from(val: Ref<'w, T>) -> Self {
Self {
value: val.value,
ticks: val.ticks,
#[cfg(feature = "track_change_detection")]
changed_by: val.changed_by,
}
}
}
impl<'w, T: Resource> From<Res<'w, T>> for Ref<'w, T> {
/// Convert a `Res` into a `Ref`. This allows keeping the change-detection feature of `Ref`
/// while losing the specificity of `Res` for resources.
fn from(res: Res<'w, T>) -> Self {
Self {
value: res.value,
ticks: res.ticks,
#[cfg(feature = "track_change_detection")]
changed_by: res.changed_by,
}
}
}
impl<'w, 'a, T: Resource> IntoIterator for &'a Res<'w, T>
where
&'a T: IntoIterator,
@ -649,6 +673,17 @@ change_detection_mut_impl!(ResMut<'w, T>, T, Resource);
impl_methods!(ResMut<'w, T>, T, Resource);
impl_debug!(ResMut<'w, T>, Resource);
impl<'w, T: Resource> From<Mut<'w, T>> for ResMut<'w, T> {
fn from(val: Mut<'w, T>) -> Self {
Self {
value: val.value,
ticks: val.ticks,
#[cfg(feature = "track_change_detection")]
changed_by: val.changed_by,
}
}
}
impl<'w, T: Resource> From<ResMut<'w, T>> for Mut<'w, T> {
/// Convert this `ResMut` into a `Mut`. This allows keeping the change-detection feature of `Mut`
/// while losing the specificity of `ResMut` for resources.