Macro planck_ecs::join [−][src]
macro_rules! join { (&$st:ident) => { ... }; (&mut $st:ident) => { ... }; ($($complex:tt)*) => { ... }; }
Expand description
The join macro makes it very easy to iterate over multiple
components of the same Entity
at once.
There are two ways to use this macro: With a single component and with multiple.
When joining over a single component, simply provide the name of the
Components<T>
instance as an immutable or mutable reference.
An iterator over the components will be returned.
The iterator will be of type &T
or &mut T
elements.
Joining over multiple components offers a complete syntax to decide which components should or should not be matched. Here is an example:
let iter = join!(&storage1 && &mut storage2 || &mut storage3 && !&storage4);
Here, we first provide a bitset. This is due to a limitation with rust macros where creating variables inside of the macro and returning them is not allowed.
Then, we tell join to join over all entities that have:
- A component in storage1
- A component in either storage2 or storage3
- No component in storage4
We also specify that storage2 and storage3 should be accessed mutably.
Finally, we can iterate:
iter.for_each(|(component1, mut component2, mut component3, _)| {});
This iterator will be of type (Option<&T1>, Option<&mut T2>, ...)
.