Skip to content

Commit e4af823

Browse files
committed
Clarify the behaviour of iter_many in the docs (#5973)
Add the following message: ``` Items are returned in the order of the list of entities. Entities that don't match the query are skipped. ``` Additionally, the docs in `iter.rs` and `state.rs` were updated to match those in `query.rs`. Co-authored-by: devil-ira <[email protected]>
1 parent c19aa59 commit e4af823

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

crates/bevy_ecs/src/query/iter.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> Iterator for QueryIter<'w, 's
7272
// This is correct as [`QueryIter`] always returns `None` once exhausted.
7373
impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> FusedIterator for QueryIter<'w, 's, Q, F> {}
7474

75-
/// An [`Iterator`] over [`Query`](crate::system::Query) results of a list of [`Entity`]s.
75+
/// An [`Iterator`] over the query items generated from an iterator of [`Entity`]s.
76+
///
77+
/// Items are returned in the order of the provided iterator.
78+
/// Entities that don't match the query are skipped.
7679
///
7780
/// This struct is created by the [`Query::iter_many`](crate::system::Query::iter_many) and [`Query::iter_many_mut`](crate::system::Query::iter_many_mut) methods.
7881
pub struct QueryManyIter<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery, I: Iterator>

crates/bevy_ecs/src/query/state.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -605,11 +605,14 @@ impl<Q: WorldQuery, F: ReadOnlyWorldQuery> QueryState<Q, F> {
605605
}
606606
}
607607

608-
/// Returns an [`Iterator`] over the query results of a list of [`Entity`]'s.
608+
/// Returns an [`Iterator`] over the read-only query items generated from an [`Entity`] list.
609609
///
610-
/// This can only return immutable data (mutable data will be cast to an immutable form).
611-
/// See [`Self::iter_many_mut`] for queries that contain at least one mutable component.
610+
/// Items are returned in the order of the list of entities.
611+
/// Entities that don't match the query are skipped.
612612
///
613+
/// # See also
614+
///
615+
/// - [`iter_many_mut`](Self::iter_many_mut) to get mutable query items.
613616
#[inline]
614617
pub fn iter_many<'w, 's, EntityList: IntoIterator>(
615618
&'s mut self,
@@ -631,7 +634,10 @@ impl<Q: WorldQuery, F: ReadOnlyWorldQuery> QueryState<Q, F> {
631634
}
632635
}
633636

634-
/// Returns an iterator over the query results of a list of [`Entity`]'s.
637+
/// Returns an iterator over the query items generated from an [`Entity`] list.
638+
///
639+
/// Items are returned in the order of the list of entities.
640+
/// Entities that don't match the query are skipped.
635641
#[inline]
636642
pub fn iter_many_mut<'w, 's, EntityList: IntoIterator>(
637643
&'s mut self,

crates/bevy_ecs/src/system/query.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,9 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> Query<'w, 's, Q, F> {
467467

468468
/// Returns an [`Iterator`] over the read-only query items generated from an [`Entity`] list.
469469
///
470+
/// Items are returned in the order of the list of entities.
471+
/// Entities that don't match the query are skipped.
472+
///
470473
/// # Example
471474
///
472475
/// ```
@@ -518,7 +521,10 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> Query<'w, 's, Q, F> {
518521
}
519522
}
520523

521-
/// Returns an [`Iterator`] over the query items generated from an [`Entity`] list.
524+
/// Returns an iterator over the query items generated from an [`Entity`] list.
525+
///
526+
/// Items are returned in the order of the list of entities.
527+
/// Entities that don't match the query are skipped.
522528
///
523529
/// # Examples
524530
///

0 commit comments

Comments
 (0)