Struct rs_ecs::Query[][src]

pub struct Query<S> where
    S: QuerySpec
{ /* fields omitted */ }
Expand description

Query to get an iterator over all entities with a certain combination of components.

Queries are provided as stand-alone structs to allow for prepared queries that can be re-used, as an optimzation. Hence, queries neet to borrow the World before their results can be iterated (see Query::borrow).

Examples

let mut world = World::new();

let entity = world.alloc();
world.insert(entity, (0_i32, true));

let entity = world.alloc();
world.insert(entity, (42_i32, 23_u32, 1.0_f32));

let mut query = Query::<(&i32, &mut bool)>::new();
for (i, b) in query.borrow(&world).iter() {
    *b = *i > 10;
}

Implementations

impl<S> Query<S> where
    S: QuerySpec
[src]

pub fn new() -> Self[src]

Create a query.

Examples

let mut immutable_query = Query::<(&i32,)>::new();
let mut mutable_query = Query::<(&i32, &mut bool)>::new();
let mut query_with_entity = Query::<(&Entity, &i32, &mut bool)>::new();

pub fn borrow<'w>(&'w mut self, world: &'w World) -> QueryRef<'w, S>[src]

Borrow the World to allow for iterating the query.

Examples

let mut world = World::new();
let mut query = Query::<(&i32, &bool)>::new();
let mut borrow = query.borrow(&world);

for (i, b) in borrow.iter() {
    println!("{}, {}", i, b);
}

pub fn with<C>(self) -> Query<With<S, C>> where
    C: 'static, 
[src]

Narrow down a query to entities that have a certain component, without borrowing that component.

For use with prepared queries, see With.

Examples

let query = Query::<(&i32,)>::new().with::<bool>();

pub fn without<C>(self) -> Query<Without<S, C>> where
    C: 'static, 
[src]

Narrow down a query to entities that do not have a certain component.

For use with prepared queries, see Without.

Examples

let query = Query::<(&i32,)>::new().without::<bool>();

Trait Implementations

impl<S> Default for Query<S> where
    S: QuerySpec
[src]

fn default() -> Self[src]

Create a query.

Auto Trait Implementations

impl<S> RefUnwindSafe for Query<S> where
    <<S as QuerySpec>::Fetch as Fetch<'static>>::Ref: RefUnwindSafe,
    <<S as QuerySpec>::Fetch as Fetch<'static>>::Ty: RefUnwindSafe

impl<S> Send for Query<S> where
    <<S as QuerySpec>::Fetch as Fetch<'static>>::Ref: Send,
    <<S as QuerySpec>::Fetch as Fetch<'static>>::Ty: Send

impl<S> Sync for Query<S> where
    <<S as QuerySpec>::Fetch as Fetch<'static>>::Ref: Sync,
    <<S as QuerySpec>::Fetch as Fetch<'static>>::Ty: Sync

impl<S> Unpin for Query<S> where
    <<S as QuerySpec>::Fetch as Fetch<'static>>::Ref: Unpin,
    <<S as QuerySpec>::Fetch as Fetch<'static>>::Ty: Unpin

impl<S> UnwindSafe for Query<S> where
    <<S as QuerySpec>::Fetch as Fetch<'static>>::Ref: UnwindSafe,
    <<S as QuerySpec>::Fetch as Fetch<'static>>::Ty: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.