[Merged by Bors] - Update ExactSizeIterator impl to support archetypal filters (With, Without)#5124
[Merged by Bors] - Update ExactSizeIterator impl to support archetypal filters (With, Without)#5124harudagondi wants to merge 6 commits intobevyengine:mainfrom
ExactSizeIterator impl to support archetypal filters (With, Without)#5124Conversation
nicopap
left a comment
There was a problem hiding this comment.
Great and simple change! Though I'd recommend having more tests. Especially to make sure the ExactSizeIterator invariant is upheld:
When implementing an
ExactSizeIterator, you must also implementIterator. When doing so, the implementation ofIterator::size_hintmust return the exact size of the iterator.
This is why I'd like to see a bit more tests:
- in
bevy_ecs_compile_test, make sure that stuff likeQuery<&Foo, Changed<Foo>>do not implementExactSizeIterator(by calling.len()on stuff and asserting a compile error) - Make sure that all following methods are equal:
query.iter().size_hint().0query.iter().size_hint().1.unwrap()query.iter().len()query.iter().count()
- Add tests for more complex query filters.
- Maybe modify as well the
ExactSizeIteratorimpl to just useself.size_hintas well.
|
Sorry, I'm not sure I understand how |
Sounds about right. Looks like it is using trybuild for testing. Need to run |
crates/bevy_ecs_compile_fail_tests/tests/ui/query_exact_sized_iterator_safety.stderr
Outdated
Show resolved
Hide resolved
alice-i-cecile
left a comment
There was a problem hiding this comment.
Nice work. I'd prefer to refactor the tests a little bit, but that's not blocking.
|
bors r+ |
…Without) (#5124) # Objective - Fixes #3142 ## Solution - Done according to #3142 - Created new marker trait `ArchetypeFilter` - Implement said trait to: - `With<T>` - `Without<T>` - tuples containing only types that implement `ArchetypeFilter`, from 0 to 15 elements - `Or<T>` where T is a tuple as described previously - Changed `ExactSizeIterator` impl to include a new generic that must implement `WorldQuery` and `ArchetypeFilter` - Added new tests --- ## Changelog ### Added - `Query`s with archetypal filters can now use `.iter().len()` to get the exact size of the iterator.
|
@superdump IIRC this was useful in a couple places for rendering; just pinging you so this is on your radar. |
ExactSizeIterator impl to support archetypal filters (With, Without)ExactSizeIterator impl to support archetypal filters (With, Without)
…Without) (bevyengine#5124) # Objective - Fixes bevyengine#3142 ## Solution - Done according to bevyengine#3142 - Created new marker trait `ArchetypeFilter` - Implement said trait to: - `With<T>` - `Without<T>` - tuples containing only types that implement `ArchetypeFilter`, from 0 to 15 elements - `Or<T>` where T is a tuple as described previously - Changed `ExactSizeIterator` impl to include a new generic that must implement `WorldQuery` and `ArchetypeFilter` - Added new tests --- ## Changelog ### Added - `Query`s with archetypal filters can now use `.iter().len()` to get the exact size of the iterator.
Following #5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`. Also: - Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`. - Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator` --- ## Changelog - Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
Following #5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`. Also: - Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`. - Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator` --- ## Changelog - Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
Following #5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`. Also: - Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`. - Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator` --- ## Changelog - Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
Following #5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`. Also: - Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`. - Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator` --- ## Changelog - Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
Following #5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`. Also: - Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`. - Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator` --- ## Changelog - Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
…Without) (bevyengine#5124) # Objective - Fixes bevyengine#3142 ## Solution - Done according to bevyengine#3142 - Created new marker trait `ArchetypeFilter` - Implement said trait to: - `With<T>` - `Without<T>` - tuples containing only types that implement `ArchetypeFilter`, from 0 to 15 elements - `Or<T>` where T is a tuple as described previously - Changed `ExactSizeIterator` impl to include a new generic that must implement `WorldQuery` and `ArchetypeFilter` - Added new tests --- ## Changelog ### Added - `Query`s with archetypal filters can now use `.iter().len()` to get the exact size of the iterator.
…ine#5148) Following bevyengine#5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`. Also: - Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`. - Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator` --- ## Changelog - Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
…Without) (bevyengine#5124) # Objective - Fixes bevyengine#3142 ## Solution - Done according to bevyengine#3142 - Created new marker trait `ArchetypeFilter` - Implement said trait to: - `With<T>` - `Without<T>` - tuples containing only types that implement `ArchetypeFilter`, from 0 to 15 elements - `Or<T>` where T is a tuple as described previously - Changed `ExactSizeIterator` impl to include a new generic that must implement `WorldQuery` and `ArchetypeFilter` - Added new tests --- ## Changelog ### Added - `Query`s with archetypal filters can now use `.iter().len()` to get the exact size of the iterator.
…ine#5148) Following bevyengine#5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`. Also: - Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`. - Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator` --- ## Changelog - Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
…Without) (bevyengine#5124) # Objective - Fixes bevyengine#3142 ## Solution - Done according to bevyengine#3142 - Created new marker trait `ArchetypeFilter` - Implement said trait to: - `With<T>` - `Without<T>` - tuples containing only types that implement `ArchetypeFilter`, from 0 to 15 elements - `Or<T>` where T is a tuple as described previously - Changed `ExactSizeIterator` impl to include a new generic that must implement `WorldQuery` and `ArchetypeFilter` - Added new tests --- ## Changelog ### Added - `Query`s with archetypal filters can now use `.iter().len()` to get the exact size of the iterator.
…ine#5148) Following bevyengine#5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`. Also: - Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`. - Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator` --- ## Changelog - Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
Objective
ExactSizeIteratorfor queries that are only filtered by With and Without #3142Solution
ExactSizeIteratorfor queries that are only filtered by With and Without #3142ArchetypeFilterWith<T>Without<T>ArchetypeFilter, from 0 to 15 elementsOr<T>where T is a tuple as described previouslyExactSizeIteratorimpl to include a new generic that must implementWorldQueryandArchetypeFilterChangelog
Added
Querys with archetypal filters can now use.iter().len()to get the exact size of the iterator.