Skip to content

Commit 7e0d262

Browse files
authored
use associated type bounds in QueryManyIter and QueryIter::sort() (#14107)
# Objective The bounds for query iterators are quite intimidating. ## Solution With Rust 1.79, [associated type bounds](rust-lang/rust#122055) stabilized, which can simplify the bounds slightly.
1 parent a58c4f7 commit 7e0d262

File tree

1 file changed

+11
-26
lines changed

1 file changed

+11
-26
lines changed

crates/bevy_ecs/src/query/iter.rs

+11-26
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,15 @@ impl<'w, 's, D: QueryData, F: QueryFilter> QueryIter<'w, 's, D, F> {
279279
/// # schedule.add_systems((system_1, system_2, system_3));
280280
/// # schedule.run(&mut world);
281281
/// ```
282-
pub fn sort<L: ReadOnlyQueryData + 'w>(
282+
pub fn sort<L: ReadOnlyQueryData<Item<'w>: Ord> + 'w>(
283283
self,
284284
) -> QuerySortedIter<
285285
'w,
286286
's,
287287
D,
288288
F,
289289
impl ExactSizeIterator<Item = Entity> + DoubleEndedIterator + FusedIterator + 'w,
290-
>
291-
where
292-
L::Item<'w>: Ord,
293-
{
290+
> {
294291
// On the first successful iteration of `QueryIterationCursor`, `archetype_entities` or `table_entities`
295292
// will be set to a non-zero value. The correctness of this method relies on this.
296293
// I.e. this sort method will execute if and only if `next` on `QueryIterationCursor` of a
@@ -376,18 +373,15 @@ impl<'w, 's, D: QueryData, F: QueryFilter> QueryIter<'w, 's, D, F> {
376373
/// # schedule.add_systems((system_1));
377374
/// # schedule.run(&mut world);
378375
/// ```
379-
pub fn sort_unstable<L: ReadOnlyQueryData + 'w>(
376+
pub fn sort_unstable<L: ReadOnlyQueryData<Item<'w>: Ord> + 'w>(
380377
self,
381378
) -> QuerySortedIter<
382379
'w,
383380
's,
384381
D,
385382
F,
386383
impl ExactSizeIterator<Item = Entity> + DoubleEndedIterator + FusedIterator + 'w,
387-
>
388-
where
389-
L::Item<'w>: Ord,
390-
{
384+
> {
391385
// On the first successful iteration of `QueryIterationCursor`, `archetype_entities` or `table_entities`
392386
// will be set to a non-zero value. The correctness of this method relies on this.
393387
// I.e. this sort method will execute if and only if `next` on `QueryIterationCursor` of a
@@ -1083,10 +1077,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator<Item = Entity>> Debug
10831077
/// Entities that don't match the query are skipped.
10841078
///
10851079
/// 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.
1086-
pub struct QueryManyIter<'w, 's, D: QueryData, F: QueryFilter, I: Iterator>
1087-
where
1088-
I::Item: Borrow<Entity>,
1089-
{
1080+
pub struct QueryManyIter<'w, 's, D: QueryData, F: QueryFilter, I: Iterator<Item: Borrow<Entity>>> {
10901081
entity_iter: I,
10911082
entities: &'w Entities,
10921083
tables: &'w Tables,
@@ -1096,9 +1087,8 @@ where
10961087
query_state: &'s QueryState<D, F>,
10971088
}
10981089

1099-
impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator> QueryManyIter<'w, 's, D, F, I>
1100-
where
1101-
I::Item: Borrow<Entity>,
1090+
impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator<Item: Borrow<Entity>>>
1091+
QueryManyIter<'w, 's, D, F, I>
11021092
{
11031093
/// # Safety
11041094
/// - `world` must have permission to access any of the components registered in `query_state`.
@@ -1196,10 +1186,8 @@ where
11961186
}
11971187
}
11981188

1199-
impl<'w, 's, D: ReadOnlyQueryData, F: QueryFilter, I: Iterator> Iterator
1189+
impl<'w, 's, D: ReadOnlyQueryData, F: QueryFilter, I: Iterator<Item: Borrow<Entity>>> Iterator
12001190
for QueryManyIter<'w, 's, D, F, I>
1201-
where
1202-
I::Item: Borrow<Entity>,
12031191
{
12041192
type Item = D::Item<'w>;
12051193

@@ -1216,16 +1204,13 @@ where
12161204
}
12171205

12181206
// This is correct as [`QueryManyIter`] always returns `None` once exhausted.
1219-
impl<'w, 's, D: ReadOnlyQueryData, F: QueryFilter, I: Iterator> FusedIterator
1207+
impl<'w, 's, D: ReadOnlyQueryData, F: QueryFilter, I: Iterator<Item: Borrow<Entity>>> FusedIterator
12201208
for QueryManyIter<'w, 's, D, F, I>
1221-
where
1222-
I::Item: Borrow<Entity>,
12231209
{
12241210
}
12251211

1226-
impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator> Debug for QueryManyIter<'w, 's, D, F, I>
1227-
where
1228-
I::Item: Borrow<Entity>,
1212+
impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator<Item: Borrow<Entity>>> Debug
1213+
for QueryManyIter<'w, 's, D, F, I>
12291214
{
12301215
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
12311216
f.debug_struct("QueryManyIter").finish()

0 commit comments

Comments
 (0)