pub struct QueryFilter {
pub requires: Vec<ComponentId>,
pub excludes: Vec<ComponentId>,
pub single: bool,
pub func: Option<QueryFunction>,
}Expand description
The QueryFilter describes the options for a crate::World query.
Fields§
§requires: Vec<ComponentId>Component types to include in the query
excludes: Vec<ComponentId>Component types to exclude from the query
single: boolWhether to match only 1 entity
func: Option<QueryFunction>Function to do additional checks on the entity
Implementations§
Source§impl QueryFilter
impl QueryFilter
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Create a new empty QueryFilter.
Examples found in repository?
examples/stress.rs (line 22)
6fn main() {
7 const ENTIIES: u64 = 1_000_000;
8 let time = SystemTime::now();
9
10 let mut world = World::new();
11
12 #[allow(dead_code)]
13 struct Number(u64);
14
15 for n in 0..=ENTIIES {
16 let id = world.spawn();
17 world.get_entity_mut(id).unwrap().add(Number(n));
18 }
19
20 for e in &Query::query_world(
21 &world,
22 QueryFilter::new()
23 .with_requires(&[component_id!(Number)])
24 .with_func(Some(|id, world| {
25 world.get_entity(id).unwrap().get::<Number>().unwrap().0 % 147 == 0
26 })),
27 ) {
28 world.despawn(e);
29 }
30
31 println!(
32 "spawning and filtering {ENTIIES} entities took {}ms",
33 time.elapsed().unwrap().as_millis()
34 );
35}Sourcepub fn with_requires(self, requires: &[ComponentId]) -> Self
pub fn with_requires(self, requires: &[ComponentId]) -> Self
Sets QueryFilter::requires field and returns the QueryFilter.
Examples found in repository?
examples/stress.rs (line 23)
6fn main() {
7 const ENTIIES: u64 = 1_000_000;
8 let time = SystemTime::now();
9
10 let mut world = World::new();
11
12 #[allow(dead_code)]
13 struct Number(u64);
14
15 for n in 0..=ENTIIES {
16 let id = world.spawn();
17 world.get_entity_mut(id).unwrap().add(Number(n));
18 }
19
20 for e in &Query::query_world(
21 &world,
22 QueryFilter::new()
23 .with_requires(&[component_id!(Number)])
24 .with_func(Some(|id, world| {
25 world.get_entity(id).unwrap().get::<Number>().unwrap().0 % 147 == 0
26 })),
27 ) {
28 world.despawn(e);
29 }
30
31 println!(
32 "spawning and filtering {ENTIIES} entities took {}ms",
33 time.elapsed().unwrap().as_millis()
34 );
35}Sourcepub fn with_excludes(self, excludes: &[ComponentId]) -> Self
pub fn with_excludes(self, excludes: &[ComponentId]) -> Self
Sets QueryFilter::excludes field and returns the QueryFilter.
Sourcepub fn with_single(self, single: bool) -> Self
pub fn with_single(self, single: bool) -> Self
Sets QueryFilter::single field and returns the QueryFilter.
Sourcepub fn with_func(self, func: Option<QueryFunction>) -> Self
pub fn with_func(self, func: Option<QueryFunction>) -> Self
Sets QueryFilter::func field and returns the QueryFilter.
Examples found in repository?
examples/stress.rs (lines 24-26)
6fn main() {
7 const ENTIIES: u64 = 1_000_000;
8 let time = SystemTime::now();
9
10 let mut world = World::new();
11
12 #[allow(dead_code)]
13 struct Number(u64);
14
15 for n in 0..=ENTIIES {
16 let id = world.spawn();
17 world.get_entity_mut(id).unwrap().add(Number(n));
18 }
19
20 for e in &Query::query_world(
21 &world,
22 QueryFilter::new()
23 .with_requires(&[component_id!(Number)])
24 .with_func(Some(|id, world| {
25 world.get_entity(id).unwrap().get::<Number>().unwrap().0 % 147 == 0
26 })),
27 ) {
28 world.despawn(e);
29 }
30
31 println!(
32 "spawning and filtering {ENTIIES} entities took {}ms",
33 time.elapsed().unwrap().as_millis()
34 );
35}Trait Implementations§
Source§impl Clone for QueryFilter
impl Clone for QueryFilter
Source§fn clone(&self) -> QueryFilter
fn clone(&self) -> QueryFilter
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for QueryFilter
impl Default for QueryFilter
Auto Trait Implementations§
impl Freeze for QueryFilter
impl RefUnwindSafe for QueryFilter
impl Send for QueryFilter
impl Sync for QueryFilter
impl Unpin for QueryFilter
impl UnwindSafe for QueryFilter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more