Query

Struct Query 

Source
pub struct Query { /* private fields */ }
Expand description

Represents how to pull specific entities and components out of the world for use by a System. Methods in a Query can be chained to create more complex queries. All chains are treated like logical ANDs.

For example, the following Query:

use thomas::{Query, TerminalTransform, Identity, Component};

#[derive(Component)]
struct CustomComponent {}

Query::new()
    .has::<TerminalTransform>()
    .has_no::<CustomComponent>()
    .has_where::<Identity>(|identity| identity.id == String::from("PLAYER"));

Will match only for entities that have a TerminalTransform, AND do NOT have a CustomComponent, AND have an Identity component where its id property equals "PLAYER", .

Implementations§

Source§

impl Query

Source

pub fn new() -> Self

Source

pub fn has<T: Component + 'static>(self) -> Self

Specifies that a matching entity must have the provided component to be a match for the query.

Source

pub fn has_no<T: Component + 'static>(self) -> Self

Specifies that a matching entity may not have the provided component to be a match for the query. Regardless of any potential matches from has, if an entity has any component specified by any has_no calls on the query, that will entirely remove that entity from the ultimate list of matches.

Source

pub fn has_where<T>(self, predicate: impl Fn(&T) -> bool + 'static) -> Self
where T: Component + 'static,

Specifies that a matching entity must have the provided component and the component must pass the provided predicate to be a match for the query.

Auto Trait Implementations§

§

impl Freeze for Query

§

impl !RefUnwindSafe for Query

§

impl !Send for Query

§

impl !Sync for Query

§

impl Unpin for Query

§

impl !UnwindSafe for Query

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.