From 96f0e02728d464ea4f74dd6001a691729f86870f Mon Sep 17 00:00:00 2001 From: Martin Svanberg Date: Sat, 14 Aug 2021 03:14:16 +0000 Subject: [PATCH] Implement Clone for Fetches (#2641) # Objective This: ```rust use bevy::prelude::*; fn main() { App::new() .add_system(test) .run(); } fn test(entities: Query) { let mut combinations = entities.iter_combinations_mut(); while let Some([e1, e2]) = combinations.fetch_next() { dbg!(e1); } } ``` fails with the message "the trait bound `bevy::ecs::query::EntityFetch: std::clone::Clone` is not satisfied". ## Solution It works after adding the naive clone implementation to EntityFetch. I'm not super familiar with ECS internals, so I'd appreciate input on this. --- crates/bevy_ecs/src/query/fetch.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs index 97bdda0462..9e20c20876 100644 --- a/crates/bevy_ecs/src/query/fetch.rs +++ b/crates/bevy_ecs/src/query/fetch.rs @@ -137,6 +137,7 @@ impl WorldQuery for Entity { } /// The [`Fetch`] of [`Entity`]. +#[derive(Clone)] pub struct EntityFetch { entities: *const Entity, } @@ -573,6 +574,7 @@ impl WorldQuery for Option { } /// The [`Fetch`] of `Option`. +#[derive(Clone)] pub struct OptionFetch { fetch: T, matches: bool, @@ -807,6 +809,21 @@ pub struct ChangeTrackersFetch { change_tick: u32, } +impl Clone for ChangeTrackersFetch { + fn clone(&self) -> Self { + Self { + storage_type: self.storage_type, + table_ticks: self.table_ticks, + entity_table_rows: self.entity_table_rows, + entities: self.entities, + sparse_set: self.sparse_set, + marker: self.marker, + last_change_tick: self.last_change_tick, + change_tick: self.change_tick, + } + } +} + /// SAFETY: access is read only unsafe impl ReadOnlyFetch for ChangeTrackersFetch {}