[][src]Trait async_ecs::join::Join

pub trait Join {
    type Type;
    type Value;
    type Mask: BitSetLike;
    pub unsafe fn open(self) -> (Self::Mask, Self::Value);
pub unsafe fn get(value: &mut Self::Value, index: Index) -> Self::Type; pub fn join(self) -> JoinIter<Self>

Notable traits for JoinIter<J>

impl<J: Join> Iterator for JoinIter<J> type Item = J::Type;

    where
        Self: Sized
, { ... }
pub fn maybe(self) -> MaybeJoin<Self>
    where
        Self: Sized
, { ... }
pub fn is_unconstrained() -> bool { ... } }

The purpose of the Join trait is to provide a way to access multiple storages at the same time with the merged bit set.

Joining component storages means that you'll only get values where for a given entity every storage has an associated component.

Example

let mut world = World::default();

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

{
    let pos = world.component::<Pos>();
    let vel = world.component::<Vel>();

    // There are no entities yet, so no pair will be returned.
    let joined: Vec<_> = (&pos, &vel).join().collect();
    assert_eq!(joined, vec![]);
}

world.create_entity().with(Pos).build();

{
    let pos = world.component::<Pos>();
    let vel = world.component::<Vel>();

    // Although there is an entity, it only has `Pos`.
    let joined: Vec<_> = (&pos, &vel).join().collect();
    assert_eq!(joined, vec![]);
}

let ent = world.create_entity().with(Pos).with(Vel).build();

{
    let pos = world.component::<Pos>();
    let vel = world.component::<Vel>();

    // Now there is one entity that has both a `Vel` and a `Pos`.
    let joined: Vec<_> = (&pos, &vel).join().collect();
    assert_eq!(joined, vec![(&Pos, &Vel)]);

    // If we want to get the entity the components are associated to,
    // we need to join over `Entities`:

    let entities = world.entities();
    // note: `Entities` is the fetched resource; we get back
    // `Read<Entities>`.
    // `Read<Entities>` can also be referred to by `Entities` which
    // is a shorthand type definition to the former type.

    let joined: Vec<_> = (&entities, &pos, &vel).join().collect();
    assert_eq!(joined, vec![(ent, &Pos, &Vel)]);
}

Iterating over a single storage

Join can also be used to iterate over a single storage, just by writing (&storage).join().

Associated Types

type Type[src]

Type of joined components.

type Value[src]

Type of joined storages.

type Mask: BitSetLike[src]

Type of joined bit mask.

Loading content...

Required methods

pub unsafe fn open(self) -> (Self::Mask, Self::Value)[src]

Open this join by returning the mask and the storages.

Safety

This is unsafe because implementations of this trait can permit the Value to be mutated independently of the Mask. If the Mask does not correctly report the status of the Value then illegal memory access can occur.

pub unsafe fn get(value: &mut Self::Value, index: Index) -> Self::Type[src]

Get a joined component value by a given index.

Safety

  • A call to get must be preceded by a check if id is part of Self::Mask
  • The implementation of this method may use unsafe code, but has no invariants to meet
Loading content...

Provided methods

pub fn join(self) -> JoinIter<Self>

Notable traits for JoinIter<J>

impl<J: Join> Iterator for JoinIter<J> type Item = J::Type;
where
    Self: Sized
[src]

Create a joined iterator over the contents.

pub fn maybe(self) -> MaybeJoin<Self> where
    Self: Sized
[src]

Returns a Join-able structure that yields all indices, returning None for all missing elements and Some(T) for found elements.

WARNING: Do not have a join of only MaybeJoins. Otherwise the join will iterate over every single index of the bitset. If you want a join with all MaybeJoins, add an Entities to the join as well to bound the join to all entities that are alive.

struct ExampleSystem;

impl<'a> System<'a> for ExampleSystem {
    type SystemData = (WriteStorage<'a, Pos>, ReadStorage<'a, Vel>);

    fn run(&mut self, (mut positions, velocities): Self::SystemData) {
        for (mut position, maybe_velocity) in (&mut positions, velocities.maybe()).join() {
            if let Some(velocity) = maybe_velocity {
                position.x += velocity.x;
                position.y += velocity.y;
            }
        }
    }
}

#[tokio::main]
async fn main() {
    let mut world = World::default();
    let mut dispatcher = Dispatcher::setup_builder(&mut world)
        .with(ExampleSystem, "example_system", &[])
        .unwrap()
        .build();

    let e1 = world
        .create_entity()
        .with(Pos { x: 0, y: 0 })
        .with(Vel { x: 5, y: 2 })
        .build();

    let e2 = world.create_entity().with(Pos { x: 0, y: 0 }).build();

    dispatcher.dispatch(&mut world).await;

    let positions = world.component::<Pos>();
    assert_eq!(positions.get(e1), Some(&Pos { x: 5, y: 2 }));
    assert_eq!(positions.get(e2), Some(&Pos { x: 0, y: 0 }));
}

pub fn is_unconstrained() -> bool[src]

If this Join typically returns all indices in the mask, then iterating over only it or combined with other joins that are also dangerous will cause the JoinIter/ParJoin to go through all indices which is usually not what is wanted and will kill performance.

Loading content...

Implementations on Foreign Types

impl<A> Join for (A,) where
    A: Join,
    (<A as Join>::Mask,): BitAnd
[src]

type Type = (A::Type,)

type Value = (A::Value,)

type Mask = <(A::Mask,) as BitAnd>::Value

impl<A, B> Join for (A, B) where
    A: Join,
    B: Join,
    (<A as Join>::Mask, <B as Join>::Mask): BitAnd
[src]

type Type = (A::Type, B::Type)

type Value = (A::Value, B::Value)

type Mask = <(A::Mask, B::Mask) as BitAnd>::Value

impl<A, B, C> Join for (A, B, C) where
    A: Join,
    B: Join,
    C: Join,
    (<A as Join>::Mask, <B as Join>::Mask, <C as Join>::Mask): BitAnd
[src]

type Type = (A::Type, B::Type, C::Type)

type Value = (A::Value, B::Value, C::Value)

type Mask = <(A::Mask, B::Mask, C::Mask) as BitAnd>::Value

impl<A, B, C, D> Join for (A, B, C, D) where
    A: Join,
    B: Join,
    C: Join,
    D: Join,
    (<A as Join>::Mask, <B as Join>::Mask, <C as Join>::Mask, <D as Join>::Mask): BitAnd
[src]

type Type = (A::Type, B::Type, C::Type, D::Type)

type Value = (A::Value, B::Value, C::Value, D::Value)

type Mask = <(A::Mask, B::Mask, C::Mask, D::Mask) as BitAnd>::Value

impl<A, B, C, D, E> Join for (A, B, C, D, E) where
    A: Join,
    B: Join,
    C: Join,
    D: Join,
    E: Join,
    (<A as Join>::Mask, <B as Join>::Mask, <C as Join>::Mask, <D as Join>::Mask, <E as Join>::Mask): BitAnd
[src]

type Type = (A::Type, B::Type, C::Type, D::Type, E::Type)

type Value = (A::Value, B::Value, C::Value, D::Value, E::Value)

type Mask = <(A::Mask, B::Mask, C::Mask, D::Mask, E::Mask) as BitAnd>::Value

impl<A, B, C, D, E, F> Join for (A, B, C, D, E, F) where
    A: Join,
    B: Join,
    C: Join,
    D: Join,
    E: Join,
    F: Join,
    (<A as Join>::Mask, <B as Join>::Mask, <C as Join>::Mask, <D as Join>::Mask, <E as Join>::Mask, <F as Join>::Mask): BitAnd
[src]

type Type = (A::Type, B::Type, C::Type, D::Type, E::Type, F::Type)

type Value = (A::Value, B::Value, C::Value, D::Value, E::Value, F::Value)

type Mask = <(A::Mask, B::Mask, C::Mask, D::Mask, E::Mask, F::Mask) as BitAnd>::Value

impl<A, B, C, D, E, F, G> Join for (A, B, C, D, E, F, G) where
    A: Join,
    B: Join,
    C: Join,
    D: Join,
    E: Join,
    F: Join,
    G: Join,
    (<A as Join>::Mask, <B as Join>::Mask, <C as Join>::Mask, <D as Join>::Mask, <E as Join>::Mask, <F as Join>::Mask, <G as Join>::Mask): BitAnd
[src]

type Type = (A::Type, B::Type, C::Type, D::Type, E::Type, F::Type, G::Type)

type Value = (A::Value, B::Value, C::Value, D::Value, E::Value, F::Value, G::Value)

type Mask = <(A::Mask, B::Mask, C::Mask, D::Mask, E::Mask, F::Mask, G::Mask) as BitAnd>::Value

impl<A, B, C, D, E, F, G, H> Join for (A, B, C, D, E, F, G, H) where
    A: Join,
    B: Join,
    C: Join,
    D: Join,
    E: Join,
    F: Join,
    G: Join,
    H: Join,
    (<A as Join>::Mask, <B as Join>::Mask, <C as Join>::Mask, <D as Join>::Mask, <E as Join>::Mask, <F as Join>::Mask, <G as Join>::Mask, <H as Join>::Mask): BitAnd
[src]

type Type = (A::Type, B::Type, C::Type, D::Type, E::Type, F::Type, G::Type, H::Type)

type Value = (A::Value, B::Value, C::Value, D::Value, E::Value, F::Value, G::Value, H::Value)

type Mask = <(A::Mask, B::Mask, C::Mask, D::Mask, E::Mask, F::Mask, G::Mask, H::Mask) as BitAnd>::Value

impl<A, B, C, D, E, F, G, H, I> Join for (A, B, C, D, E, F, G, H, I) where
    A: Join,
    B: Join,
    C: Join,
    D: Join,
    E: Join,
    F: Join,
    G: Join,
    H: Join,
    I: Join,
    (<A as Join>::Mask, <B as Join>::Mask, <C as Join>::Mask, <D as Join>::Mask, <E as Join>::Mask, <F as Join>::Mask, <G as Join>::Mask, <H as Join>::Mask, <I as Join>::Mask): BitAnd
[src]

type Type = (A::Type, B::Type, C::Type, D::Type, E::Type, F::Type, G::Type, H::Type, I::Type)

type Value = (A::Value, B::Value, C::Value, D::Value, E::Value, F::Value, G::Value, H::Value, I::Value)

type Mask = <(A::Mask, B::Mask, C::Mask, D::Mask, E::Mask, F::Mask, G::Mask, H::Mask, I::Mask) as BitAnd>::Value

impl<A, B, C, D, E, F, G, H, I, J> Join for (A, B, C, D, E, F, G, H, I, J) where
    A: Join,
    B: Join,
    C: Join,
    D: Join,
    E: Join,
    F: Join,
    G: Join,
    H: Join,
    I: Join,
    J: Join,
    (<A as Join>::Mask, <B as Join>::Mask, <C as Join>::Mask, <D as Join>::Mask, <E as Join>::Mask, <F as Join>::Mask, <G as Join>::Mask, <H as Join>::Mask, <I as Join>::Mask, <J as Join>::Mask): BitAnd
[src]

type Type = (A::Type, B::Type, C::Type, D::Type, E::Type, F::Type, G::Type, H::Type, I::Type, J::Type)

type Value = (A::Value, B::Value, C::Value, D::Value, E::Value, F::Value, G::Value, H::Value, I::Value, J::Value)

type Mask = <(A::Mask, B::Mask, C::Mask, D::Mask, E::Mask, F::Mask, G::Mask, H::Mask, I::Mask, J::Mask) as BitAnd>::Value

impl<A, B, C, D, E, F, G, H, I, J, K> Join for (A, B, C, D, E, F, G, H, I, J, K) where
    A: Join,
    B: Join,
    C: Join,
    D: Join,
    E: Join,
    F: Join,
    G: Join,
    H: Join,
    I: Join,
    J: Join,
    K: Join,
    (<A as Join>::Mask, <B as Join>::Mask, <C as Join>::Mask, <D as Join>::Mask, <E as Join>::Mask, <F as Join>::Mask, <G as Join>::Mask, <H as Join>::Mask, <I as Join>::Mask, <J as Join>::Mask, <K as Join>::Mask): BitAnd
[src]

type Type = (A::Type, B::Type, C::Type, D::Type, E::Type, F::Type, G::Type, H::Type, I::Type, J::Type, K::Type)

type Value = (A::Value, B::Value, C::Value, D::Value, E::Value, F::Value, G::Value, H::Value, I::Value, J::Value, K::Value)

type Mask = <(A::Mask, B::Mask, C::Mask, D::Mask, E::Mask, F::Mask, G::Mask, H::Mask, I::Mask, J::Mask, K::Mask) as BitAnd>::Value

impl<A, B, C, D, E, F, G, H, I, J, K, L> Join for (A, B, C, D, E, F, G, H, I, J, K, L) where
    A: Join,
    B: Join,
    C: Join,
    D: Join,
    E: Join,
    F: Join,
    G: Join,
    H: Join,
    I: Join,
    J: Join,
    K: Join,
    L: Join,
    (<A as Join>::Mask, <B as Join>::Mask, <C as Join>::Mask, <D as Join>::Mask, <E as Join>::Mask, <F as Join>::Mask, <G as Join>::Mask, <H as Join>::Mask, <I as Join>::Mask, <J as Join>::Mask, <K as Join>::Mask, <L as Join>::Mask): BitAnd
[src]

type Type = (A::Type, B::Type, C::Type, D::Type, E::Type, F::Type, G::Type, H::Type, I::Type, J::Type, K::Type, L::Type)

type Value = (A::Value, B::Value, C::Value, D::Value, E::Value, F::Value, G::Value, H::Value, I::Value, J::Value, K::Value, L::Value)

type Mask = <(A::Mask, B::Mask, C::Mask, D::Mask, E::Mask, F::Mask, G::Mask, H::Mask, I::Mask, J::Mask, K::Mask, L::Mask) as BitAnd>::Value

impl<A, B, C, D, E, F, G, H, I, J, K, L, M> Join for (A, B, C, D, E, F, G, H, I, J, K, L, M) where
    A: Join,
    B: Join,
    C: Join,
    D: Join,
    E: Join,
    F: Join,
    G: Join,
    H: Join,
    I: Join,
    J: Join,
    K: Join,
    L: Join,
    M: Join,
    (<A as Join>::Mask, <B as Join>::Mask, <C as Join>::Mask, <D as Join>::Mask, <E as Join>::Mask, <F as Join>::Mask, <G as Join>::Mask, <H as Join>::Mask, <I as Join>::Mask, <J as Join>::Mask, <K as Join>::Mask, <L as Join>::Mask, <M as Join>::Mask): BitAnd
[src]

type Type = (A::Type, B::Type, C::Type, D::Type, E::Type, F::Type, G::Type, H::Type, I::Type, J::Type, K::Type, L::Type, M::Type)

type Value = (A::Value, B::Value, C::Value, D::Value, E::Value, F::Value, G::Value, H::Value, I::Value, J::Value, K::Value, L::Value, M::Value)

type Mask = <(A::Mask, B::Mask, C::Mask, D::Mask, E::Mask, F::Mask, G::Mask, H::Mask, I::Mask, J::Mask, K::Mask, L::Mask, M::Mask) as BitAnd>::Value

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N> Join for (A, B, C, D, E, F, G, H, I, J, K, L, M, N) where
    A: Join,
    B: Join,
    C: Join,
    D: Join,
    E: Join,
    F: Join,
    G: Join,
    H: Join,
    I: Join,
    J: Join,
    K: Join,
    L: Join,
    M: Join,
    N: Join,
    (<A as Join>::Mask, <B as Join>::Mask, <C as Join>::Mask, <D as Join>::Mask, <E as Join>::Mask, <F as Join>::Mask, <G as Join>::Mask, <H as Join>::Mask, <I as Join>::Mask, <J as Join>::Mask, <K as Join>::Mask, <L as Join>::Mask, <M as Join>::Mask, <N as Join>::Mask): BitAnd
[src]

type Type = (A::Type, B::Type, C::Type, D::Type, E::Type, F::Type, G::Type, H::Type, I::Type, J::Type, K::Type, L::Type, M::Type, N::Type)

type Value = (A::Value, B::Value, C::Value, D::Value, E::Value, F::Value, G::Value, H::Value, I::Value, J::Value, K::Value, L::Value, M::Value, N::Value)

type Mask = <(A::Mask, B::Mask, C::Mask, D::Mask, E::Mask, F::Mask, G::Mask, H::Mask, I::Mask, J::Mask, K::Mask, L::Mask, M::Mask, N::Mask) as BitAnd>::Value

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O> Join for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O) where
    A: Join,
    B: Join,
    C: Join,
    D: Join,
    E: Join,
    F: Join,
    G: Join,
    H: Join,
    I: Join,
    J: Join,
    K: Join,
    L: Join,
    M: Join,
    N: Join,
    O: Join,
    (<A as Join>::Mask, <B as Join>::Mask, <C as Join>::Mask, <D as Join>::Mask, <E as Join>::Mask, <F as Join>::Mask, <G as Join>::Mask, <H as Join>::Mask, <I as Join>::Mask, <J as Join>::Mask, <K as Join>::Mask, <L as Join>::Mask, <M as Join>::Mask, <N as Join>::Mask, <O as Join>::Mask): BitAnd
[src]

type Type = (A::Type, B::Type, C::Type, D::Type, E::Type, F::Type, G::Type, H::Type, I::Type, J::Type, K::Type, L::Type, M::Type, N::Type, O::Type)

type Value = (A::Value, B::Value, C::Value, D::Value, E::Value, F::Value, G::Value, H::Value, I::Value, J::Value, K::Value, L::Value, M::Value, N::Value, O::Value)

type Mask = <(A::Mask, B::Mask, C::Mask, D::Mask, E::Mask, F::Mask, G::Mask, H::Mask, I::Mask, J::Mask, K::Mask, L::Mask, M::Mask, N::Mask, O::Mask) as BitAnd>::Value

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> Join for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) where
    A: Join,
    B: Join,
    C: Join,
    D: Join,
    E: Join,
    F: Join,
    G: Join,
    H: Join,
    I: Join,
    J: Join,
    K: Join,
    L: Join,
    M: Join,
    N: Join,
    O: Join,
    P: Join,
    (<A as Join>::Mask, <B as Join>::Mask, <C as Join>::Mask, <D as Join>::Mask, <E as Join>::Mask, <F as Join>::Mask, <G as Join>::Mask, <H as Join>::Mask, <I as Join>::Mask, <J as Join>::Mask, <K as Join>::Mask, <L as Join>::Mask, <M as Join>::Mask, <N as Join>::Mask, <O as Join>::Mask, <P as Join>::Mask): BitAnd
[src]

type Type = (A::Type, B::Type, C::Type, D::Type, E::Type, F::Type, G::Type, H::Type, I::Type, J::Type, K::Type, L::Type, M::Type, N::Type, O::Type, P::Type)

type Value = (A::Value, B::Value, C::Value, D::Value, E::Value, F::Value, G::Value, H::Value, I::Value, J::Value, K::Value, L::Value, M::Value, N::Value, O::Value, P::Value)

type Mask = <(A::Mask, B::Mask, C::Mask, D::Mask, E::Mask, F::Mask, G::Mask, H::Mask, I::Mask, J::Mask, K::Mask, L::Mask, M::Mask, N::Mask, O::Mask, P::Mask) as BitAnd>::Value

Loading content...

Implementors

impl<'a> Join for &'a Entities[src]

type Mask = &'a BitSet

type Type = Entity

type Value = Self

impl<'a> Join for AntiStorage<'a>[src]

type Mask = BitSetNot<&'a BitSet>

type Type = ()

type Value = ()

impl<'a, 'b, T> Join for &'a Read<'b, T> where
    &'a T: Join,
    T: Resource
[src]

type Type = <&'a T as Join>::Type

type Value = <&'a T as Join>::Value

type Mask = <&'a T as Join>::Mask

impl<'a, 'b, T> Join for &'a Ref<'b, T> where
    &'a T: Join,
    T: Resource
[src]

type Type = <&'a T as Join>::Type

type Value = <&'a T as Join>::Value

type Mask = <&'a T as Join>::Mask

impl<'a, 'b, T> Join for &'a mut Write<'b, T> where
    &'a mut T: Join,
    T: Resource
[src]

type Type = <&'a mut T as Join>::Type

type Value = <&'a mut T as Join>::Value

type Mask = <&'a mut T as Join>::Mask

impl<'a, 'b, T> Join for &'a mut RefMut<'b, T> where
    &'a mut T: Join,
    T: Resource
[src]

type Type = <&'a mut T as Join>::Type

type Value = <&'a mut T as Join>::Value

type Mask = <&'a mut T as Join>::Mask

impl<'a, 'e, T, D> Join for &'a StorageWrapper<'e, T, D> where
    T: Component,
    D: Deref<Target = MaskedStorage<T>>, 
[src]

type Mask = &'a BitSet

type Type = &'a T

type Value = &'a T::Storage

impl<'a, 'e, T, D> Join for &'a mut StorageWrapper<'e, T, D> where
    T: Component,
    D: DerefMut<Target = MaskedStorage<T>>, 
[src]

type Mask = &'a BitSet

type Type = &'a mut T

type Value = &'a T::Storage

impl<'a, T> Join for Drain<'a, T> where
    T: Component
[src]

type Mask = BitSet

type Type = T

type Value = &'a mut MaskedStorage<T>

impl<T> Join for MaybeJoin<T> where
    T: Join
[src]

type Mask = BitSetAll

type Type = Option<<T as Join>::Type>

type Value = (<T as Join>::Mask, <T as Join>::Value)

Loading content...