mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 15:14:50 +00:00
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:
parent
6aedb2500a
commit
96f0e02728
1 changed files with 17 additions and 0 deletions
|
@ -137,6 +137,7 @@ impl WorldQuery for Entity {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The [`Fetch`] of [`Entity`].
|
/// The [`Fetch`] of [`Entity`].
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct EntityFetch {
|
pub struct EntityFetch {
|
||||||
entities: *const Entity,
|
entities: *const Entity,
|
||||||
}
|
}
|
||||||
|
@ -573,6 +574,7 @@ impl<T: WorldQuery> WorldQuery for Option<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The [`Fetch`] of `Option<T>`.
|
/// The [`Fetch`] of `Option<T>`.
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct OptionFetch<T> {
|
pub struct OptionFetch<T> {
|
||||||
fetch: T,
|
fetch: T,
|
||||||
matches: bool,
|
matches: bool,
|
||||||
|
@ -807,6 +809,21 @@ pub struct ChangeTrackersFetch<T> {
|
||||||
change_tick: u32,
|
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
|
/// SAFETY: access is read only
|
||||||
unsafe impl<T> ReadOnlyFetch for ChangeTrackersFetch<T> {}
|
unsafe impl<T> ReadOnlyFetch for ChangeTrackersFetch<T> {}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue