Deprecated Query::many and many_mut (#18183)

# Objective

Alternative to and closes #18120.

Sibling to #18082, see that PR for broader reasoning.

Folks weren't sold on the name `many` (get_many is clearer, and this is
rare), and that PR is much more complex.

## Solution

- Simply deprecate `Query::many` and `Query::many_mut`
- Clean up internal usages

Mentions of this in the docs can wait until it's fully removed in the
0.17 cycle IMO: it's much easier to catch the problems when doing that.

## Testing

CI!

## Migration Guide

`Query::many` and `Query::many_mut` have been deprecated to reduce
panics and API duplication. Use `Query::get_many` and
`Query::get_many_mut` instead, and handle the `Result`.

---------

Co-authored-by: Chris Russell <8494645+chescock@users.noreply.github.com>
This commit is contained in:
Alice Cecile 2025-03-06 21:10:32 -05:00 committed by GitHub
parent 664000f848
commit 5bc1d68a65
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 1 deletions

View File

@ -777,7 +777,6 @@ mod tests {
let _: Option<&Foo> = q.get(e).ok(); let _: Option<&Foo> = q.get(e).ok();
let _: Option<[&Foo; 1]> = q.get_many([e]).ok(); let _: Option<[&Foo; 1]> = q.get_many([e]).ok();
let _: Option<&Foo> = q.single().ok(); let _: Option<&Foo> = q.single().ok();
let _: [&Foo; 1] = q.many([e]);
let _: &Foo = q.single().unwrap(); let _: &Foo = q.single().unwrap();
} }

View File

@ -1377,6 +1377,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> {
/// - [`get_many`](Self::get_many) for the non-panicking version. /// - [`get_many`](Self::get_many) for the non-panicking version.
#[inline] #[inline]
#[track_caller] #[track_caller]
#[deprecated(note = "Use `get_many` instead and handle the Result.")]
pub fn many<const N: usize>(&self, entities: [Entity; N]) -> [ROQueryItem<'_, D>; N] { pub fn many<const N: usize>(&self, entities: [Entity; N]) -> [ROQueryItem<'_, D>; N] {
match self.get_many(entities) { match self.get_many(entities) {
Ok(items) => items, Ok(items) => items,
@ -1682,6 +1683,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> {
/// - [`many`](Self::many) to get read-only query items. /// - [`many`](Self::many) to get read-only query items.
#[inline] #[inline]
#[track_caller] #[track_caller]
#[deprecated(note = "Use `get_many_mut` instead and handle the Result.")]
pub fn many_mut<const N: usize>(&mut self, entities: [Entity; N]) -> [D::Item<'_>; N] { pub fn many_mut<const N: usize>(&mut self, entities: [Entity; N]) -> [D::Item<'_>; N] {
match self.get_many_mut(entities) { match self.get_many_mut(entities) {
Ok(items) => items, Ok(items) => items,