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](https://github.com/rust-lang/rust/pull/122055/) stabilized, which can simplify the bounds slightly.
This commit is contained in:
parent
a58c4f7825
commit
7e0d262d77
@ -279,7 +279,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> QueryIter<'w, 's, D, F> {
|
|||||||
/// # schedule.add_systems((system_1, system_2, system_3));
|
/// # schedule.add_systems((system_1, system_2, system_3));
|
||||||
/// # schedule.run(&mut world);
|
/// # schedule.run(&mut world);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn sort<L: ReadOnlyQueryData + 'w>(
|
pub fn sort<L: ReadOnlyQueryData<Item<'w>: Ord> + 'w>(
|
||||||
self,
|
self,
|
||||||
) -> QuerySortedIter<
|
) -> QuerySortedIter<
|
||||||
'w,
|
'w,
|
||||||
@ -287,10 +287,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> QueryIter<'w, 's, D, F> {
|
|||||||
D,
|
D,
|
||||||
F,
|
F,
|
||||||
impl ExactSizeIterator<Item = Entity> + DoubleEndedIterator + FusedIterator + 'w,
|
impl ExactSizeIterator<Item = Entity> + DoubleEndedIterator + FusedIterator + 'w,
|
||||||
>
|
> {
|
||||||
where
|
|
||||||
L::Item<'w>: Ord,
|
|
||||||
{
|
|
||||||
// On the first successful iteration of `QueryIterationCursor`, `archetype_entities` or `table_entities`
|
// On the first successful iteration of `QueryIterationCursor`, `archetype_entities` or `table_entities`
|
||||||
// will be set to a non-zero value. The correctness of this method relies on this.
|
// will be set to a non-zero value. The correctness of this method relies on this.
|
||||||
// I.e. this sort method will execute if and only if `next` on `QueryIterationCursor` of a
|
// I.e. this sort method will execute if and only if `next` on `QueryIterationCursor` of a
|
||||||
@ -376,7 +373,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> QueryIter<'w, 's, D, F> {
|
|||||||
/// # schedule.add_systems((system_1));
|
/// # schedule.add_systems((system_1));
|
||||||
/// # schedule.run(&mut world);
|
/// # schedule.run(&mut world);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn sort_unstable<L: ReadOnlyQueryData + 'w>(
|
pub fn sort_unstable<L: ReadOnlyQueryData<Item<'w>: Ord> + 'w>(
|
||||||
self,
|
self,
|
||||||
) -> QuerySortedIter<
|
) -> QuerySortedIter<
|
||||||
'w,
|
'w,
|
||||||
@ -384,10 +381,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> QueryIter<'w, 's, D, F> {
|
|||||||
D,
|
D,
|
||||||
F,
|
F,
|
||||||
impl ExactSizeIterator<Item = Entity> + DoubleEndedIterator + FusedIterator + 'w,
|
impl ExactSizeIterator<Item = Entity> + DoubleEndedIterator + FusedIterator + 'w,
|
||||||
>
|
> {
|
||||||
where
|
|
||||||
L::Item<'w>: Ord,
|
|
||||||
{
|
|
||||||
// On the first successful iteration of `QueryIterationCursor`, `archetype_entities` or `table_entities`
|
// On the first successful iteration of `QueryIterationCursor`, `archetype_entities` or `table_entities`
|
||||||
// will be set to a non-zero value. The correctness of this method relies on this.
|
// will be set to a non-zero value. The correctness of this method relies on this.
|
||||||
// I.e. this sort method will execute if and only if `next` on `QueryIterationCursor` of a
|
// 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
|
|||||||
/// Entities that don't match the query are skipped.
|
/// 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, D: QueryData, F: QueryFilter, I: Iterator>
|
pub struct QueryManyIter<'w, 's, D: QueryData, F: QueryFilter, I: Iterator<Item: Borrow<Entity>>> {
|
||||||
where
|
|
||||||
I::Item: Borrow<Entity>,
|
|
||||||
{
|
|
||||||
entity_iter: I,
|
entity_iter: I,
|
||||||
entities: &'w Entities,
|
entities: &'w Entities,
|
||||||
tables: &'w Tables,
|
tables: &'w Tables,
|
||||||
@ -1096,9 +1087,8 @@ where
|
|||||||
query_state: &'s QueryState<D, F>,
|
query_state: &'s QueryState<D, F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator> QueryManyIter<'w, 's, D, F, I>
|
impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator<Item: Borrow<Entity>>>
|
||||||
where
|
QueryManyIter<'w, 's, D, F, I>
|
||||||
I::Item: Borrow<Entity>,
|
|
||||||
{
|
{
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// - `world` must have permission to access any of the components registered in `query_state`.
|
/// - `world` must have permission to access any of the components registered in `query_state`.
|
||||||
@ -1196,10 +1186,8 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'w, 's, D: ReadOnlyQueryData, F: QueryFilter, I: Iterator> Iterator
|
impl<'w, 's, D: ReadOnlyQueryData, F: QueryFilter, I: Iterator<Item: Borrow<Entity>>> Iterator
|
||||||
for QueryManyIter<'w, 's, D, F, I>
|
for QueryManyIter<'w, 's, D, F, I>
|
||||||
where
|
|
||||||
I::Item: Borrow<Entity>,
|
|
||||||
{
|
{
|
||||||
type Item = D::Item<'w>;
|
type Item = D::Item<'w>;
|
||||||
|
|
||||||
@ -1216,16 +1204,13 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This is correct as [`QueryManyIter`] always returns `None` once exhausted.
|
// This is correct as [`QueryManyIter`] always returns `None` once exhausted.
|
||||||
impl<'w, 's, D: ReadOnlyQueryData, F: QueryFilter, I: Iterator> FusedIterator
|
impl<'w, 's, D: ReadOnlyQueryData, F: QueryFilter, I: Iterator<Item: Borrow<Entity>>> FusedIterator
|
||||||
for QueryManyIter<'w, 's, D, F, I>
|
for QueryManyIter<'w, 's, D, F, I>
|
||||||
where
|
|
||||||
I::Item: Borrow<Entity>,
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator> Debug for QueryManyIter<'w, 's, D, F, I>
|
impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator<Item: Borrow<Entity>>> Debug
|
||||||
where
|
for QueryManyIter<'w, 's, D, F, I>
|
||||||
I::Item: Borrow<Entity>,
|
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
f.debug_struct("QueryManyIter").finish()
|
f.debug_struct("QueryManyIter").finish()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user