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 <justthecooldude@gmail.com>
This commit is contained in:
ira 2022-10-24 13:46:38 +00:00
parent c19aa5939d
commit e4af823b45
3 changed files with 21 additions and 6 deletions

View File

@ -72,7 +72,10 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> Iterator for QueryIter<'w, 's
// This is correct as [`QueryIter`] always returns `None` once exhausted. // This is correct as [`QueryIter`] always returns `None` once exhausted.
impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> FusedIterator for QueryIter<'w, 's, Q, F> {} impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> FusedIterator for QueryIter<'w, 's, Q, F> {}
/// An [`Iterator`] over [`Query`](crate::system::Query) results of a list of [`Entity`]s. /// An [`Iterator`] over the query items generated from an iterator of [`Entity`]s.
///
/// Items are returned in the order of the provided iterator.
/// Entities that don't match the query are skipped.
/// ///
/// 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. /// 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.
pub struct QueryManyIter<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery, I: Iterator> pub struct QueryManyIter<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery, I: Iterator>

View File

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

View File

@ -467,6 +467,9 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> Query<'w, 's, Q, F> {
/// Returns an [`Iterator`] over the read-only query items generated from an [`Entity`] list. /// Returns an [`Iterator`] over the read-only query items generated from an [`Entity`] list.
/// ///
/// Items are returned in the order of the list of entities.
/// Entities that don't match the query are skipped.
///
/// # Example /// # Example
/// ///
/// ``` /// ```
@ -518,7 +521,10 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> Query<'w, 's, Q, F> {
} }
} }
/// Returns an [`Iterator`] over the query items generated from an [`Entity`] list. /// Returns an iterator over the query items generated from an [`Entity`] list.
///
/// Items are returned in the order of the list of entities.
/// Entities that don't match the query are skipped.
/// ///
/// # Examples /// # Examples
/// ///