Skip to content

Commit

Permalink
add Res::clone (bevyengine#4109)
Browse files Browse the repository at this point in the history
# 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`
  • Loading branch information
BoxyUwU authored and james7132 committed Oct 28, 2022
1 parent 44a94fd commit 7a07a8f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/bevy_ecs/src/system/system_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7a07a8f

Please sign in to comment.