Skip to content

Commit 4d4170d

Browse files
authored
Implement IntoIterator for Populated and borrows (#19441)
# Objective `Populated`, a loose wrapper around `Query`, does not implement `IntoIterator`, requiring either a deref or `into_inner()` call to access the `Query` and iterate over that. ## Solution This pr implements `IntoIterator` for `Populated`, `&Populated`, and `&mut Populated`, each of which forwards the call to the inner `Query`. This allows the `Populated` to be used directly for any API that takes an `impl IntoIterator`. ## Testing `cargo test` was run on the `bevy_ecs` crate ``` test result: ok. 390 passed; 0 failed; 2 ignored; 0 measured; 0 filtered out; finished in 46.38s ```
1 parent 415f6d8 commit 4d4170d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

crates/bevy_ecs/src/system/query.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,6 +2627,36 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Populated<'w, 's, D, F> {
26272627
}
26282628
}
26292629

2630+
impl<'w, 's, D: QueryData, F: QueryFilter> IntoIterator for Populated<'w, 's, D, F> {
2631+
type Item = <Query<'w, 's, D, F> as IntoIterator>::Item;
2632+
2633+
type IntoIter = <Query<'w, 's, D, F> as IntoIterator>::IntoIter;
2634+
2635+
fn into_iter(self) -> Self::IntoIter {
2636+
self.0.into_iter()
2637+
}
2638+
}
2639+
2640+
impl<'a, 'w, 's, D: QueryData, F: QueryFilter> IntoIterator for &'a Populated<'w, 's, D, F> {
2641+
type Item = <&'a Query<'w, 's, D, F> as IntoIterator>::Item;
2642+
2643+
type IntoIter = <&'a Query<'w, 's, D, F> as IntoIterator>::IntoIter;
2644+
2645+
fn into_iter(self) -> Self::IntoIter {
2646+
self.deref().into_iter()
2647+
}
2648+
}
2649+
2650+
impl<'a, 'w, 's, D: QueryData, F: QueryFilter> IntoIterator for &'a mut Populated<'w, 's, D, F> {
2651+
type Item = <&'a mut Query<'w, 's, D, F> as IntoIterator>::Item;
2652+
2653+
type IntoIter = <&'a mut Query<'w, 's, D, F> as IntoIterator>::IntoIter;
2654+
2655+
fn into_iter(self) -> Self::IntoIter {
2656+
self.deref_mut().into_iter()
2657+
}
2658+
}
2659+
26302660
#[cfg(test)]
26312661
mod tests {
26322662
use crate::{prelude::*, query::QueryEntityError};

0 commit comments

Comments
 (0)