From 7a07a8f761eec3da533c52f718bb79a797c1622c Mon Sep 17 00:00:00 2001 From: Boxy Date: Tue, 27 Sep 2022 18:48:25 +0000 Subject: [PATCH] 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` --- crates/bevy_ecs/src/system/system_param.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index 01f317e3ed6b7..6f57b2dd0e4a6 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -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)