Skip to content

Commit 96f0e02

Browse files
committed
Implement Clone for Fetches (#2641)
# Objective This: ```rust use bevy::prelude::*; fn main() { App::new() .add_system(test) .run(); } fn test(entities: Query<Entity>) { 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.
1 parent 6aedb25 commit 96f0e02

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

crates/bevy_ecs/src/query/fetch.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ impl WorldQuery for Entity {
137137
}
138138

139139
/// The [`Fetch`] of [`Entity`].
140+
#[derive(Clone)]
140141
pub struct EntityFetch {
141142
entities: *const Entity,
142143
}
@@ -573,6 +574,7 @@ impl<T: WorldQuery> WorldQuery for Option<T> {
573574
}
574575

575576
/// The [`Fetch`] of `Option<T>`.
577+
#[derive(Clone)]
576578
pub struct OptionFetch<T> {
577579
fetch: T,
578580
matches: bool,
@@ -807,6 +809,21 @@ pub struct ChangeTrackersFetch<T> {
807809
change_tick: u32,
808810
}
809811

812+
impl<T> Clone for ChangeTrackersFetch<T> {
813+
fn clone(&self) -> Self {
814+
Self {
815+
storage_type: self.storage_type,
816+
table_ticks: self.table_ticks,
817+
entity_table_rows: self.entity_table_rows,
818+
entities: self.entities,
819+
sparse_set: self.sparse_set,
820+
marker: self.marker,
821+
last_change_tick: self.last_change_tick,
822+
change_tick: self.change_tick,
823+
}
824+
}
825+
}
826+
810827
/// SAFETY: access is read only
811828
unsafe impl<T> ReadOnlyFetch for ChangeTrackersFetch<T> {}
812829

0 commit comments

Comments
 (0)