add Res::clone (#4109)

# Objective
Make `Res` cloneable
## Solution
Add an associated fn `clone(self: &Self) -. Self` instead of `Copy + Clone` trait impls to avoid `res.clone()` failing to clone out the underlying `T`
This commit is contained in:
Boxy 2022-09-27 18:48:25 +00:00
parent 263ab9424d
commit 92c90a9bad

View file

@ -291,6 +291,17 @@ where
}
impl<'w, T: Resource> Res<'w, T> {
// no it shouldn't clippy
#[allow(clippy::should_implement_trait)]
pub fn clone(this: &Self) -> Self {
Self {
value: this.value,
ticks: this.ticks,
last_change_tick: this.last_change_tick,
change_tick: this.change_tick,
}
}
/// Returns `true` if the resource was added after the system last ran.
pub fn is_added(&self) -> bool {
self.ticks.is_added(self.last_change_tick, self.change_tick)