Skip to content

Commit 5dc8686

Browse files
committed
Rename WorldQueryFilter to QueryFilter
1 parent 5a3ad48 commit 5dc8686

File tree

18 files changed

+111
-111
lines changed

18 files changed

+111
-111
lines changed

crates/bevy_ecs/macros/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,8 @@ pub fn derive_world_query_data(input: TokenStream) -> TokenStream {
456456
derive_world_query_data_impl(input)
457457
}
458458

459-
/// Implement `WorldQueryFilter` to use a struct as a filter parameter in a query
460-
#[proc_macro_derive(WorldQueryFilter, attributes(world_query_filter))]
459+
/// Implement `QueryFilter` to use a struct as a filter parameter in a query
460+
#[proc_macro_derive(QueryFilter, attributes(query_filter))]
461461
pub fn derive_world_query_filter(input: TokenStream) -> TokenStream {
462462
derive_world_query_filter_impl(input)
463463
}

crates/bevy_ecs/macros/src/world_query_filter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub fn derive_world_query_filter_impl(input: TokenStream) -> TokenStream {
120120
);
121121

122122
let filter_impl = quote! {
123-
impl #user_impl_generics #path::query::WorldQueryFilter
123+
impl #user_impl_generics #path::query::QueryFilter
124124
for #struct_name #user_ty_generics #user_where_clauses {
125125
const IS_ARCHETYPAL: bool = true #(&& <#field_types>::IS_ARCHETYPAL)*;
126126

@@ -163,7 +163,7 @@ pub fn derive_world_query_filter_impl(input: TokenStream) -> TokenStream {
163163

164164
fn assert_filter<T>()
165165
where
166-
T: #path::query::WorldQueryFilter,
166+
T: #path::query::QueryFilter,
167167
{
168168
}
169169

crates/bevy_ecs/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ mod tests {
6464
change_detection::Ref,
6565
component::{Component, ComponentId},
6666
entity::Entity,
67-
query::{Added, Changed, FilteredAccess, With, Without, WorldQueryFilter},
67+
query::{Added, Changed, FilteredAccess, QueryFilter, With, Without},
6868
system::Resource,
6969
world::{EntityRef, Mut, World},
7070
};
@@ -903,7 +903,7 @@ mod tests {
903903
}
904904
}
905905

906-
fn get_filtered<F: WorldQueryFilter>(world: &mut World) -> Vec<Entity> {
906+
fn get_filtered<F: QueryFilter>(world: &mut World) -> Vec<Entity> {
907907
world
908908
.query_filtered::<Entity, F>()
909909
.iter(world)
@@ -986,7 +986,7 @@ mod tests {
986986
}
987987
}
988988

989-
fn get_filtered<F: WorldQueryFilter>(world: &mut World) -> Vec<Entity> {
989+
fn get_filtered<F: QueryFilter>(world: &mut World) -> Vec<Entity> {
990990
world
991991
.query_filtered::<Entity, F>()
992992
.iter(world)

crates/bevy_ecs/src/query/filter.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,29 @@ use std::{cell::UnsafeCell, marker::PhantomData};
1717
/// [`With`] and [`Without`] filters can be applied to check if the queried entity does or does not contain a particular component.
1818
/// - **Change detection filters.**
1919
/// [`Added`] and [`Changed`] filters can be applied to detect component changes to an entity.
20-
/// - **`WorldQueryFilter` tuples.**
21-
/// If every element of a tuple implements `WorldQueryFilter`, then the tuple itself also implements the same trait.
20+
/// - **`QueryFilter` tuples.**
21+
/// If every element of a tuple implements `QueryFilter`, then the tuple itself also implements the same trait.
2222
/// This enables a single `Query` to filter over multiple conditions.
2323
/// Due to the current lack of variadic generics in Rust, the trait has been implemented for tuples from 0 to 15 elements,
24-
/// but nesting of tuples allows infinite `WorldQueryFilter`s.
24+
/// but nesting of tuples allows infinite `QueryFilter`s.
2525
/// - **Filter disjunction operator.**
2626
/// By default, tuples compose query filters in such a way that all conditions must be satisfied to generate a query item for a given entity.
2727
/// Wrapping a tuple inside an [`Or`] operator will relax the requirement to just one condition.
2828
///
2929
/// Implementing the trait manually can allow for a fundamentally new type of behavior.
3030
///
31-
/// Query design can be easily structured by deriving `WorldQueryFilter` for custom types.
32-
/// Despite the added complexity, this approach has several advantages over using `WorldQueryFilter` tuples.
31+
/// Query design can be easily structured by deriving `QueryFilter` for custom types.
32+
/// Despite the added complexity, this approach has several advantages over using `QueryFilter` tuples.
3333
/// The most relevant improvements are:
3434
///
3535
/// - Reusability across multiple systems.
3636
/// - Filters can be composed together to create a more complex filter.
3737
///
38-
/// This trait can only be derived for structs if each field also implements `WorldQueryFilter`.
38+
/// This trait can only be derived for structs if each field also implements `QueryFilter`.
3939
///
4040
/// ```
4141
/// # use bevy_ecs::prelude::*;
42-
/// # use bevy_ecs::{query::WorldQueryFilter, component::Component};
42+
/// # use bevy_ecs::{query::QueryFilter, component::Component};
4343
/// #
4444
/// # #[derive(Component)]
4545
/// # struct ComponentA;
@@ -52,7 +52,7 @@ use std::{cell::UnsafeCell, marker::PhantomData};
5252
/// # #[derive(Component)]
5353
/// # struct ComponentE;
5454
/// #
55-
/// #[derive(WorldQueryFilter)]
55+
/// #[derive(QueryFilter)]
5656
/// struct MyFilter<T: Component, P: Component> {
5757
/// // Field names are not relevant, since they are never manually accessed.
5858
/// with_a: With<ComponentA>,
@@ -77,7 +77,7 @@ use std::{cell::UnsafeCell, marker::PhantomData};
7777
/// [`With`]: crate::query::With
7878
/// [`Without`]: crate::query::Without
7979
80-
pub trait WorldQueryFilter: WorldQuery {
80+
pub trait QueryFilter: WorldQuery {
8181
/// Returns true if (and only if) this Filter relies strictly on archetypes to limit which
8282
/// components are accessed by the Query.
8383
///
@@ -199,7 +199,7 @@ unsafe impl<T: Component> WorldQuery for With<T> {
199199
}
200200
}
201201

202-
impl<T: Component> WorldQueryFilter for With<T> {
202+
impl<T: Component> QueryFilter for With<T> {
203203
const IS_ARCHETYPAL: bool = true;
204204

205205
#[inline(always)]
@@ -311,7 +311,7 @@ unsafe impl<T: Component> WorldQuery for Without<T> {
311311
}
312312
}
313313

314-
impl<T: Component> WorldQueryFilter for Without<T> {
314+
impl<T: Component> QueryFilter for Without<T> {
315315
const IS_ARCHETYPAL: bool = true;
316316

317317
#[inline(always)]
@@ -381,7 +381,7 @@ macro_rules! impl_query_filter_tuple {
381381
/// This is sound because `update_component_access` and `update_archetype_component_access` adds accesses according to the implementations of all the subqueries.
382382
/// `update_component_access` replace the filters with a disjunction where every element is a conjunction of the previous filters and the filters of one of the subqueries.
383383
/// This is sound because `matches_component_set` returns a disjunction of the results of the subqueries' implementations.
384-
unsafe impl<$($filter: WorldQueryFilter),*> WorldQuery for Or<($($filter,)*)> {
384+
unsafe impl<$($filter: QueryFilter),*> WorldQuery for Or<($($filter,)*)> {
385385
type Fetch<'w> = ($(OrFetch<'w, $filter>,)*);
386386
type Item<'w> = bool;
387387
type State = ($($filter::State,)*);
@@ -475,7 +475,7 @@ macro_rules! impl_query_filter_tuple {
475475
}
476476
}
477477

478-
impl<$($filter: WorldQueryFilter),*> WorldQueryFilter for Or<($($filter,)*)> {
478+
impl<$($filter: QueryFilter),*> QueryFilter for Or<($($filter,)*)> {
479479
const IS_ARCHETYPAL: bool = true $(&& $filter::IS_ARCHETYPAL)*;
480480

481481
#[inline(always)]
@@ -496,7 +496,7 @@ macro_rules! impl_tuple_world_query_filter {
496496
#[allow(non_snake_case)]
497497
#[allow(clippy::unused_unit)]
498498

499-
impl<$($name: WorldQueryFilter),*> WorldQueryFilter for ($($name,)*) {
499+
impl<$($name: QueryFilter),*> QueryFilter for ($($name,)*) {
500500
const IS_ARCHETYPAL: bool = true $(&& $name::IS_ARCHETYPAL)*;
501501

502502
#[inline(always)]
@@ -674,7 +674,7 @@ unsafe impl<T: Component> WorldQuery for Added<T> {
674674
}
675675
}
676676

677-
impl<T: Component> WorldQueryFilter for Added<T> {
677+
impl<T: Component> QueryFilter for Added<T> {
678678
const IS_ARCHETYPAL: bool = false;
679679
#[inline(always)]
680680
unsafe fn filter_fetch(
@@ -850,7 +850,7 @@ unsafe impl<T: Component> WorldQuery for Changed<T> {
850850
}
851851
}
852852

853-
impl<T: Component> WorldQueryFilter for Changed<T> {
853+
impl<T: Component> QueryFilter for Changed<T> {
854854
const IS_ARCHETYPAL: bool = false;
855855

856856
#[inline(always)]
@@ -868,14 +868,14 @@ impl<T: Component> WorldQueryFilter for Changed<T> {
868868
/// This is needed to implement [`ExactSizeIterator`] for
869869
/// [`QueryIter`](crate::query::QueryIter) that contains archetype-level filters.
870870
///
871-
/// The trait must only be implemented for filters where its corresponding [`WorldQueryFilter::IS_ARCHETYPAL`]
871+
/// The trait must only be implemented for filters where its corresponding [`QueryFilter::IS_ARCHETYPAL`]
872872
/// is [`prim@true`]. As such, only the [`With`] and [`Without`] filters can implement the trait.
873873
/// [Tuples](prim@tuple) and [`Or`] filters are automatically implemented with the trait only if its containing types
874874
/// also implement the same trait.
875875
///
876876
/// [`Added`] and [`Changed`] works with entities, and therefore are not archetypal. As such
877877
/// they do not implement [`ArchetypeFilter`].
878-
pub trait ArchetypeFilter: WorldQueryFilter {}
878+
pub trait ArchetypeFilter: QueryFilter {}
879879

880880
impl<T: Component> ArchetypeFilter for With<T> {}
881881
impl<T: Component> ArchetypeFilter for Without<T> {}

crates/bevy_ecs/src/query/iter.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ use crate::{
88
};
99
use std::{borrow::Borrow, iter::FusedIterator, mem::MaybeUninit};
1010

11-
use super::{QueryData, ReadOnlyQueryData, WorldQueryFilter};
11+
use super::{QueryData, QueryFilter, ReadOnlyQueryData};
1212

1313
/// An [`Iterator`] over query results of a [`Query`](crate::system::Query).
1414
///
1515
/// This struct is created by the [`Query::iter`](crate::system::Query::iter) and
1616
/// [`Query::iter_mut`](crate::system::Query::iter_mut) methods.
17-
pub struct QueryIter<'w, 's, Q: QueryData, F: WorldQueryFilter> {
17+
pub struct QueryIter<'w, 's, Q: QueryData, F: QueryFilter> {
1818
tables: &'w Tables,
1919
archetypes: &'w Archetypes,
2020
query_state: &'s QueryState<Q, F>,
2121
cursor: QueryIterationCursor<'w, 's, Q, F>,
2222
}
2323

24-
impl<'w, 's, Q: QueryData, F: WorldQueryFilter> QueryIter<'w, 's, Q, F> {
24+
impl<'w, 's, Q: QueryData, F: QueryFilter> QueryIter<'w, 's, Q, F> {
2525
/// # Safety
2626
/// - `world` must have permission to access any of the components registered in `query_state`.
2727
/// - `world` must be the same one used to initialize `query_state`.
@@ -41,7 +41,7 @@ impl<'w, 's, Q: QueryData, F: WorldQueryFilter> QueryIter<'w, 's, Q, F> {
4141
}
4242
}
4343

44-
impl<'w, 's, Q: QueryData, F: WorldQueryFilter> Iterator for QueryIter<'w, 's, Q, F> {
44+
impl<'w, 's, Q: QueryData, F: QueryFilter> Iterator for QueryIter<'w, 's, Q, F> {
4545
type Item = Q::Item<'w>;
4646

4747
#[inline(always)]
@@ -64,15 +64,15 @@ impl<'w, 's, Q: QueryData, F: WorldQueryFilter> Iterator for QueryIter<'w, 's, Q
6464
}
6565

6666
// This is correct as [`QueryIter`] always returns `None` once exhausted.
67-
impl<'w, 's, Q: QueryData, F: WorldQueryFilter> FusedIterator for QueryIter<'w, 's, Q, F> {}
67+
impl<'w, 's, Q: QueryData, F: QueryFilter> FusedIterator for QueryIter<'w, 's, Q, F> {}
6868

6969
/// An [`Iterator`] over the query items generated from an iterator of [`Entity`]s.
7070
///
7171
/// Items are returned in the order of the provided iterator.
7272
/// Entities that don't match the query are skipped.
7373
///
7474
/// 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.
75-
pub struct QueryManyIter<'w, 's, Q: QueryData, F: WorldQueryFilter, I: Iterator>
75+
pub struct QueryManyIter<'w, 's, Q: QueryData, F: QueryFilter, I: Iterator>
7676
where
7777
I::Item: Borrow<Entity>,
7878
{
@@ -85,7 +85,7 @@ where
8585
query_state: &'s QueryState<Q, F>,
8686
}
8787

88-
impl<'w, 's, Q: QueryData, F: WorldQueryFilter, I: Iterator> QueryManyIter<'w, 's, Q, F, I>
88+
impl<'w, 's, Q: QueryData, F: QueryFilter, I: Iterator> QueryManyIter<'w, 's, Q, F, I>
8989
where
9090
I::Item: Borrow<Entity>,
9191
{
@@ -181,7 +181,7 @@ where
181181
}
182182
}
183183

184-
impl<'w, 's, Q: ReadOnlyQueryData, F: WorldQueryFilter, I: Iterator> Iterator
184+
impl<'w, 's, Q: ReadOnlyQueryData, F: QueryFilter, I: Iterator> Iterator
185185
for QueryManyIter<'w, 's, Q, F, I>
186186
where
187187
I::Item: Borrow<Entity>,
@@ -201,7 +201,7 @@ where
201201
}
202202

203203
// This is correct as [`QueryManyIter`] always returns `None` once exhausted.
204-
impl<'w, 's, Q: ReadOnlyQueryData, F: WorldQueryFilter, I: Iterator> FusedIterator
204+
impl<'w, 's, Q: ReadOnlyQueryData, F: QueryFilter, I: Iterator> FusedIterator
205205
for QueryManyIter<'w, 's, Q, F, I>
206206
where
207207
I::Item: Borrow<Entity>,
@@ -271,16 +271,14 @@ where
271271
/// [`Query`]: crate::system::Query
272272
/// [`Query::iter_combinations`]: crate::system::Query::iter_combinations
273273
/// [`Query::iter_combinations_mut`]: crate::system::Query::iter_combinations_mut
274-
pub struct QueryCombinationIter<'w, 's, Q: QueryData, F: WorldQueryFilter, const K: usize> {
274+
pub struct QueryCombinationIter<'w, 's, Q: QueryData, F: QueryFilter, const K: usize> {
275275
tables: &'w Tables,
276276
archetypes: &'w Archetypes,
277277
query_state: &'s QueryState<Q, F>,
278278
cursors: [QueryIterationCursor<'w, 's, Q, F>; K],
279279
}
280280

281-
impl<'w, 's, Q: QueryData, F: WorldQueryFilter, const K: usize>
282-
QueryCombinationIter<'w, 's, Q, F, K>
283-
{
281+
impl<'w, 's, Q: QueryData, F: QueryFilter, const K: usize> QueryCombinationIter<'w, 's, Q, F, K> {
284282
/// # Safety
285283
/// - `world` must have permission to access any of the components registered in `query_state`.
286284
/// - `world` must be the same one used to initialize `query_state`.
@@ -385,7 +383,7 @@ impl<'w, 's, Q: QueryData, F: WorldQueryFilter, const K: usize>
385383
// Iterator type is intentionally implemented only for read-only access.
386384
// Doing so for mutable references would be unsound, because calling `next`
387385
// multiple times would allow multiple owned references to the same data to exist.
388-
impl<'w, 's, Q: ReadOnlyQueryData, F: WorldQueryFilter, const K: usize> Iterator
386+
impl<'w, 's, Q: ReadOnlyQueryData, F: QueryFilter, const K: usize> Iterator
389387
for QueryCombinationIter<'w, 's, Q, F, K>
390388
{
391389
type Item = [Q::Item<'w>; K];
@@ -428,7 +426,7 @@ impl<'w, 's, Q: ReadOnlyQueryData, F: WorldQueryFilter, const K: usize> Iterator
428426
}
429427
}
430428

431-
impl<'w, 's, Q: QueryData, F: WorldQueryFilter> ExactSizeIterator for QueryIter<'w, 's, Q, F>
429+
impl<'w, 's, Q: QueryData, F: QueryFilter> ExactSizeIterator for QueryIter<'w, 's, Q, F>
432430
where
433431
F: ArchetypeFilter,
434432
{
@@ -438,12 +436,12 @@ where
438436
}
439437

440438
// This is correct as [`QueryCombinationIter`] always returns `None` once exhausted.
441-
impl<'w, 's, Q: ReadOnlyQueryData, F: WorldQueryFilter, const K: usize> FusedIterator
439+
impl<'w, 's, Q: ReadOnlyQueryData, F: QueryFilter, const K: usize> FusedIterator
442440
for QueryCombinationIter<'w, 's, Q, F, K>
443441
{
444442
}
445443

446-
struct QueryIterationCursor<'w, 's, Q: QueryData, F: WorldQueryFilter> {
444+
struct QueryIterationCursor<'w, 's, Q: QueryData, F: QueryFilter> {
447445
table_id_iter: std::slice::Iter<'s, TableId>,
448446
archetype_id_iter: std::slice::Iter<'s, ArchetypeId>,
449447
table_entities: &'w [Entity],
@@ -456,7 +454,7 @@ struct QueryIterationCursor<'w, 's, Q: QueryData, F: WorldQueryFilter> {
456454
current_row: usize,
457455
}
458456

459-
impl<Q: QueryData, F: WorldQueryFilter> Clone for QueryIterationCursor<'_, '_, Q, F> {
457+
impl<Q: QueryData, F: QueryFilter> Clone for QueryIterationCursor<'_, '_, Q, F> {
460458
fn clone(&self) -> Self {
461459
Self {
462460
table_id_iter: self.table_id_iter.clone(),
@@ -471,7 +469,7 @@ impl<Q: QueryData, F: WorldQueryFilter> Clone for QueryIterationCursor<'_, '_, Q
471469
}
472470
}
473471

474-
impl<'w, 's, Q: QueryData, F: WorldQueryFilter> QueryIterationCursor<'w, 's, Q, F> {
472+
impl<'w, 's, Q: QueryData, F: QueryFilter> QueryIterationCursor<'w, 's, Q, F> {
475473
const IS_DENSE: bool = Q::IS_DENSE && F::IS_DENSE;
476474

477475
unsafe fn init_empty(

crates/bevy_ecs/src/query/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod state;
1010
mod world_query;
1111

1212
pub use access::*;
13-
pub use bevy_ecs_macros::{QueryData, WorldQueryFilter};
13+
pub use bevy_ecs_macros::{QueryData, QueryFilter};
1414
pub use error::*;
1515
pub use fetch::*;
1616
pub use filter::*;
@@ -67,7 +67,7 @@ impl<T> DebugCheckedUnwrap for Option<T> {
6767

6868
#[cfg(test)]
6969
mod tests {
70-
use bevy_ecs_macros::{QueryData, WorldQueryFilter};
70+
use bevy_ecs_macros::{QueryData, QueryFilter};
7171

7272
use crate::prelude::{AnyOf, Changed, Entity, Or, QueryState, With, Without};
7373
use crate::query::{ArchetypeFilter, Has, QueryCombinationIter, ReadOnlyQueryData};
@@ -618,11 +618,11 @@ mod tests {
618618
}
619619

620620
{
621-
#[derive(WorldQueryFilter)]
621+
#[derive(QueryFilter)]
622622
struct AOrBFilter {
623623
a: Or<(With<A>, With<B>)>,
624624
}
625-
#[derive(WorldQueryFilter)]
625+
#[derive(QueryFilter)]
626626
struct NoSparseThatsSlow {
627627
no: Without<Sparse>,
628628
}
@@ -639,7 +639,7 @@ mod tests {
639639
}
640640

641641
{
642-
#[derive(WorldQueryFilter)]
642+
#[derive(QueryFilter)]
643643
struct CSparseFilter {
644644
tuple_structs_pls: With<C>,
645645
ugh: With<Sparse>,
@@ -657,7 +657,7 @@ mod tests {
657657
}
658658

659659
{
660-
#[derive(WorldQueryFilter)]
660+
#[derive(QueryFilter)]
661661
struct WithoutComps {
662662
_1: Without<A>,
663663
_2: Without<B>,

0 commit comments

Comments
 (0)