Struct rs_ecs::QueryMap

source ·
pub struct QueryMap<'q, S>
where S: QuerySpec,
{ /* private fields */ }
Expand description

Provides random access to the entities which match a certain Query.

Implementations§

source§

impl<S> QueryMap<'_, S>
where S: QuerySpec,

source

pub fn contains(&self, ent: Entity) -> bool

Check if an Entity is present in the map.

In contrast to get, this does not require a S::Fetch: FetchShared bound. In contrast to get_mut however, a shared borrow is sufficient.

§Examples
let mut world = World::new();

let entity1 = world.alloc();
world.insert(entity1, (42_i32, 1.0_f32));

let entity2 = world.alloc();
world.insert(entity2, (2.0_f32,));

let mut query = Query::<(&i32, Option<&f32>)>::new();
let mut query = query.borrow(&world);
let query = query.map();

assert!(query.contains(entity1));
assert!(!query.contains(entity2));
source

pub fn get(&self, ent: Entity) -> Option<<S::Fetch as Fetch<'_>>::Item>
where S::Fetch: FetchShared,

Access the queried components of the given Entity

Available only if the components do not include unique references.

§Examples
let mut world = World::new();

let entity1 = world.alloc();
world.insert(entity1, (42_i32, 1.0_f32));

let entity2 = world.alloc();
world.insert(entity2, (23_i32,));

let mut query = Query::<(&i32, Option<&f32>)>::new();
let mut query = query.borrow(&world);
let mut query = query.map();

let (i1, f1) = query.get(entity1).unwrap();
let (i2, f2) = query.get(entity2).unwrap();

assert_eq!(*i1, 42);
assert_eq!(f1.copied(), Some(1.0));
assert_eq!(*i2, 23);
assert_eq!(f2.copied(), None);
source

pub fn get_mut(&mut self, ent: Entity) -> Option<<S::Fetch as Fetch<'_>>::Item>

Exclusively access the queried components of the given Entity

source

pub fn get_many_mut<const N: usize>( &mut self, ent: [Entity; N] ) -> [Option<<S::Fetch as Fetch<'_>>::Item>; N]

Exclusively access the queried component of the given distinct entities

§Examples
let mut world = World::new();

let entity1 = world.alloc();
world.insert(entity1, (42_i32, 1.0_f32));

let entity2 = world.alloc();
world.insert(entity2, (23_i32,));

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

let [i1, i2] = query.get_many_mut([entity1, entity2]);

assert_eq!(*i1.unwrap(), 42);
assert_eq!(*i2.unwrap(), 23);

Trait Implementations§

source§

impl<'q, S> Send for QueryMap<'q, S>
where S: QuerySpec, <S::Fetch as Fetch<'q>>::Item: Send,

source§

impl<'q, S> Sync for QueryMap<'q, S>
where S: QuerySpec, <S::Fetch as Fetch<'q>>::Item: Send,

Auto Trait Implementations§

§

impl<'q, S> RefUnwindSafe for QueryMap<'q, S>
where <<S as QuerySpec>::Fetch as Fetch<'q>>::Ptr: RefUnwindSafe,

§

impl<'q, S> Unpin for QueryMap<'q, S>

§

impl<'q, S> UnwindSafe for QueryMap<'q, S>
where <<S as QuerySpec>::Fetch as Fetch<'q>>::Ptr: RefUnwindSafe,

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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

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>,

§

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.