-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update
ExactSizeIterator
impl to support archetypal filters (With, …
…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.
- Loading branch information
1 parent
e28b88b
commit 6e50b24
Showing
5 changed files
with
218 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
crates/bevy_ecs_compile_fail_tests/tests/ui/query_exact_sized_iterator_safety.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use bevy_ecs::prelude::*; | ||
|
||
#[derive(Component)] | ||
struct Foo; | ||
|
||
fn on_changed(query: Query<&Foo, Changed<Foo>>) { | ||
// this should fail to compile | ||
is_exact_size_iterator(query.iter()); | ||
} | ||
|
||
fn on_added(query: Query<&Foo, Added<Foo>>) { | ||
// this should fail to compile | ||
is_exact_size_iterator(query.iter()); | ||
} | ||
|
||
fn is_exact_size_iterator<T: ExactSizeIterator>(_iter: T) {} | ||
|
||
fn main() {} |
29 changes: 29 additions & 0 deletions
29
crates/bevy_ecs_compile_fail_tests/tests/ui/query_exact_sized_iterator_safety.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
error[E0277]: the trait bound `bevy_ecs::query::Changed<Foo>: ArchetypeFilter` is not satisfied | ||
--> tests/ui/query_exact_sized_iterator_safety.rs:8:28 | ||
| | ||
8 | is_exact_size_iterator(query.iter()); | ||
| ---------------------- ^^^^^^^^^^^^ the trait `ArchetypeFilter` is not implemented for `bevy_ecs::query::Changed<Foo>` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= note: required because of the requirements on the impl of `ExactSizeIterator` for `QueryIter<'_, '_, &Foo, ReadFetch<'_, Foo>, bevy_ecs::query::Changed<Foo>>` | ||
note: required by a bound in `is_exact_size_iterator` | ||
--> tests/ui/query_exact_sized_iterator_safety.rs:16:30 | ||
| | ||
16 | fn is_exact_size_iterator<T: ExactSizeIterator>(_iter: T) {} | ||
| ^^^^^^^^^^^^^^^^^ required by this bound in `is_exact_size_iterator` | ||
|
||
error[E0277]: the trait bound `bevy_ecs::query::Added<Foo>: ArchetypeFilter` is not satisfied | ||
--> tests/ui/query_exact_sized_iterator_safety.rs:13:28 | ||
| | ||
13 | is_exact_size_iterator(query.iter()); | ||
| ---------------------- ^^^^^^^^^^^^ the trait `ArchetypeFilter` is not implemented for `bevy_ecs::query::Added<Foo>` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= note: required because of the requirements on the impl of `ExactSizeIterator` for `QueryIter<'_, '_, &Foo, ReadFetch<'_, Foo>, bevy_ecs::query::Added<Foo>>` | ||
note: required by a bound in `is_exact_size_iterator` | ||
--> tests/ui/query_exact_sized_iterator_safety.rs:16:30 | ||
| | ||
16 | fn is_exact_size_iterator<T: ExactSizeIterator>(_iter: T) {} | ||
| ^^^^^^^^^^^^^^^^^ required by this bound in `is_exact_size_iterator` |