Expand description
ECS-style query builder for iterating entities by component composition. ECS-style query builder for iterating entities by component composition.
§Examples
use elevator_core::prelude::*;
use elevator_core::query::{Ext, With, Without};
use serde::{Serialize, Deserialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
struct VipTag { level: u32 }
let mut sim = SimulationBuilder::demo().build().unwrap();
let rider_eid = sim.spawn_rider_by_stop_id(StopId(0), StopId(1), 75.0).unwrap();
// Attach an extension component.
sim.world_mut().insert_ext(rider_eid, VipTag { level: 5 }, "vip_tag");
let world = sim.world();
// All riders with a position
for (id, rider, pos) in world.query::<(EntityId, &Rider, &Position)>().iter() {
println!("{id:?}: phase={:?} at {}", rider.phase(), pos.value());
}
// Entities with Position but without Route
for (id, pos) in world.query::<(EntityId, &Position)>()
.without::<Route>()
.iter()
{
println!("{id:?} at {}", pos.value());
}
// Extension components (cloned)
for (id, vip) in world.query::<(EntityId, &Ext<VipTag>)>().iter() {
println!("VIP rider {id:?}: level {}", vip.level);
}Structs§
- Ext
- Marker type for querying extension components.
- ExtMut
- Marker type for mutable extension queries.
- ExtQuery
Mut - Builder for mutable extension queries.
- ExtWith
- Include only entities that have extension component
T. - ExtWithout
- Exclude entities that have extension component
T. - Query
Builder - Builder for constructing and executing queries.
- Query
Iter - Iterator over entities matching a query and its filters.
- With
- Include only entities that have built-in component
T. - Without
- Exclude entities that have built-in component
T.
Traits§
- Query
Filter - Filter trait for restricting which entities a query matches.
- World
Query - Describes what data a query fetches for each matching entity.