[][src]Struct specs::join::JoinIter

#[must_use]
pub struct JoinIter<J: Join> { /* fields omitted */ }

JoinIter is an Iterator over a group of Storages.

Methods

impl<J: Join> JoinIter<J>[src]

pub fn new(j: J) -> Self[src]

Create a new join iterator.

impl<J: Join> JoinIter<J>[src]

pub fn get(&mut self, entity: Entity, entities: &Entities) -> Option<J::Type>[src]

Allows getting joined values for specific entity.

Example

let mut world = World::new();

world.register::<Pos>();
world.register::<Vel>();

// This entity could be stashed anywhere (into `Component`, `Resource`, `System`s data, etc.) as it's just a number.
let entity = world
    .create_entity()
    .with(Pos)
    .with(Vel)
    .build();

// Later
{
    let mut pos = world.write_storage::<Pos>();
    let vel = world.read_storage::<Vel>();

    assert_eq!(
        Some((&mut Pos, &Vel)),
        (&mut pos, &vel).join().get(entity, &world.entities()),
        "The entity that was stashed still has the needed components and is alive."
    );
}

// The entity has found nice spot and doesn't need to move anymore.
world.write_storage::<Vel>().remove(entity);

// Even later
{
    let mut pos = world.write_storage::<Pos>();
    let vel = world.read_storage::<Vel>();

    assert_eq!(
        None,
        (&mut pos, &vel).join().get(entity, &world.entities()),
        "The entity doesn't have velocity anymore."
    );
}

pub fn get_unchecked(&mut self, index: Index) -> Option<J::Type>[src]

Allows getting joined values for specific raw index.

The raw index for an Entity can be retrieved using Entity::id method.

As this method operates on raw indices, there is no check to see if the entity is still alive, so the caller should ensure it instead.

Trait Implementations

impl<J: Join> Clone for JoinIter<J> where
    J::Mask: Clone,
    J::Value: Clone
[src]

Clones the JoinIter.

Examples

let mut world = World::new();

world.register::<Position>();
world.register::<Collider>();

// add some entities to our world
for _ in 0..10 {
    let entity = world
        .create_entity()
        .with(Position)
        .with(Collider)
        .build();   
}

// check for collisions between entities
let positions = world.read_storage::<Position>();
let colliders = world.read_storage::<Collider>();
 
let mut join_iter = (&positions, &colliders).join();
while let Some(a) = join_iter.next() {
    for b in join_iter.clone() {
        if check_collision(a, b) {
            // do stuff
        }
    }
}

It is not possible to clone a JoinIter which allows for mutation of its content, as this would lead to shared mutable access.

This example deliberately fails to compile
// .. previous example
 
let mut positions = world.write_storage::<Position>();
 
let mut join_iter = (&mut positions).join();
// this must not compile, as the following line would cause
// undefined behavior!
let mut cloned_iter = join_iter.clone();
let (mut alias_one, mut alias_two) = (join_iter.next(), cloned_iter.next());

impl<J: Join> Iterator for JoinIter<J>[src]

type Item = J::Type

The type of the elements being iterated over.

Auto Trait Implementations

impl<J> RefUnwindSafe for JoinIter<J> where
    <J as Join>::Mask: RefUnwindSafe,
    <J as Join>::Value: RefUnwindSafe

impl<J> Send for JoinIter<J> where
    <J as Join>::Mask: Send,
    <J as Join>::Value: Send

impl<J> Sync for JoinIter<J> where
    <J as Join>::Mask: Sync,
    <J as Join>::Value: Sync

impl<J> Unpin for JoinIter<J> where
    <J as Join>::Mask: Unpin,
    <J as Join>::Value: Unpin

impl<J> UnwindSafe for JoinIter<J> where
    <J as Join>::Mask: UnwindSafe,
    <J as Join>::Value: UnwindSafe

Blanket Implementations

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

impl<T> Any for T where
    T: Any

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

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

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

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

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

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<I> IteratorRandom for I where
    I: Iterator
[src]

impl<T> ParallelBridge for T where
    T: Send + Iterator,
    <T as Iterator>::Item: Send
[src]

impl<T> Resource for T where
    T: Any + Send + Sync
[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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,