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.
This commit is contained in:
Martin Svanberg 2021-08-14 03:14:16 +00:00
parent 6aedb2500a
commit 96f0e02728

View file

@ -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<T: WorldQuery> WorldQuery for Option<T> {
}
/// The [`Fetch`] of `Option<T>`.
#[derive(Clone)]
pub struct OptionFetch<T> {
fetch: T,
matches: bool,
@ -807,6 +809,21 @@ pub struct ChangeTrackersFetch<T> {
change_tick: u32,
}
impl<T> Clone for ChangeTrackersFetch<T> {
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<T> ReadOnlyFetch for ChangeTrackersFetch<T> {}