[][src]Struct yaks::QueryMarker

pub struct QueryMarker<Q0>(_)
where
    Q0: Query
;

A zero-sized Copy type used to describe queries of a system, and prepare them via methods of SystemContext.

Instantiating these directly is only useful when calling systems as plain functions, and can be done either by QueryMarker::new(), QueryMarker::default(), or Default::default(), the latter of which can also instantiate tuples of markers (up to 10):

fn single_query(context: SystemContext, average: &mut f32, query: QueryMarker<&f32>) {
    *average = 0f32;
    let mut entities = 0;
    for (_entity, value) in context.query(query).iter() {
        entities += 1;
        *average += *value;
    }
    *average /= entities as f32;
}

single_query(world.into(), &mut average, QueryMarker::new());
single_query(world.into(), &mut average, QueryMarker::default());
single_query(world.into(), &mut average, Default::default());

fn two_queries(
    context: SystemContext,
    average: &mut f32,
    (floats, ints): (QueryMarker<&f32>, QueryMarker<&i32>),
) {
    *average = 0f32;
    let mut entities = 0;
    for (_entity, value) in context.query(floats).iter() {
        entities += 1;
        *average += *value;
    }
    for (_entity, value) in context.query(ints).iter() {
        entities += 1;
        *average += *value as f32;
    }
    *average /= entities as f32;
}

two_queries(world.into(), &mut average, Default::default());

Instantiating markers inside a system is improper!

While it's possible to instantiate a marker within a system and use it to prepare a query, doing so does not inform the executor the system may be in of said query, and may lead to a panic.

Implementations

impl<Q0> QueryMarker<Q0> where
    Q0: Query
[src]

pub fn new() -> Self[src]

Equivalent to QueryMarker::default(). See documentation for QueryMarker itself.

Trait Implementations

impl<Q0> Clone for QueryMarker<Q0> where
    Q0: Query
[src]

impl<Q0> Copy for QueryMarker<Q0> where
    Q0: Query
[src]

impl<Q0> Default for QueryMarker<Q0> where
    Q0: Query
[src]

Auto Trait Implementations

impl<Q0> RefUnwindSafe for QueryMarker<Q0> where
    Q0: RefUnwindSafe

impl<Q0> Send for QueryMarker<Q0> where
    Q0: Send

impl<Q0> Sync for QueryMarker<Q0> where
    Q0: Sync

impl<Q0> Unpin for QueryMarker<Q0> where
    Q0: Unpin

impl<Q0> UnwindSafe for QueryMarker<Q0> where
    Q0: UnwindSafe

Blanket Implementations

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

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

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

impl<T> Component for T where
    T: 'static + Send + Sync
[src]

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

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.

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.