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 ```
This commit is contained in:
parent
415f6d8ca7
commit
4d4170d834
@ -2627,6 +2627,36 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Populated<'w, 's, D, F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'w, 's, D: QueryData, F: QueryFilter> IntoIterator for Populated<'w, 's, D, F> {
|
||||
type Item = <Query<'w, 's, D, F> as IntoIterator>::Item;
|
||||
|
||||
type IntoIter = <Query<'w, 's, D, F> as IntoIterator>::IntoIter;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.0.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'w, 's, D: QueryData, F: QueryFilter> IntoIterator for &'a Populated<'w, 's, D, F> {
|
||||
type Item = <&'a Query<'w, 's, D, F> as IntoIterator>::Item;
|
||||
|
||||
type IntoIter = <&'a Query<'w, 's, D, F> as IntoIterator>::IntoIter;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.deref().into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'w, 's, D: QueryData, F: QueryFilter> IntoIterator for &'a mut Populated<'w, 's, D, F> {
|
||||
type Item = <&'a mut Query<'w, 's, D, F> as IntoIterator>::Item;
|
||||
|
||||
type IntoIter = <&'a mut Query<'w, 's, D, F> as IntoIterator>::IntoIter;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.deref_mut().into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{prelude::*, query::QueryEntityError};
|
||||
|
Loading…
Reference in New Issue
Block a user