zero_ecs/
lib.rs

1pub use itertools::chain;
2pub use itertools::izip;
3pub use macro_magic;
4
5pub use macro_magic::export_tokens;
6pub use macro_magic::{import_tokens, import_tokens_attr, import_tokens_proc};
7
8pub use extend::ext;
9pub use rayon;
10pub use rayon::prelude::*;
11pub use std::marker::PhantomData;
12pub use zero_ecs_macros::ecs_world;
13pub use zero_ecs_macros::entity;
14pub use zero_ecs_macros::expand_world;
15pub use zero_ecs_macros::make_query;
16pub use zero_ecs_macros::query;
17pub use zero_ecs_macros::system;
18pub use zero_ecs_macros::system_for_each;
19pub use zero_ecs_macros::tag_world;
20
21pub use derive_more;
22pub use derive_more::From;
23pub use derive_more::Into;
24
25#[macro_export]
26macro_rules! izip_par {
27    // @closure creates a tuple-flattening closure for .map() call. usage:
28    // @closure partial_pattern => partial_tuple , rest , of , iterators
29    // eg. izip!( @closure ((a, b), c) => (a, b, c) , dd , ee )
30    ( @closure $p:pat => $tup:expr ) => {
31        |$p| $tup
32    };
33
34    // The "b" identifier is a different identifier on each recursion level thanks to hygiene.
35    ( @closure $p:pat => ( $($tup:tt)* ) , $_iter:expr $( , $tail:expr )* ) => {
36        $crate::izip_par!(@closure ($p, b) => ( $($tup)*, b ) $( , $tail )*)
37    };
38
39    // unary
40    ($first:expr $(,)*) => {
41        $crate::IntoParallelIterator::into_par_iter($first)
42    };
43
44    // binary
45    ($first:expr, $second:expr $(,)*) => {
46        $crate::izip_par!($first)
47            .zip($second)
48    };
49
50    // n-ary where n > 2
51    ( $first:expr $( , $rest:expr )* $(,)* ) => {
52        $crate::izip_par!($first)
53            $(
54                .zip($rest)
55            )*
56            .map(
57                $crate::izip!(@closure a => (a) $( , $rest )*)
58            )
59    };
60}
61#[macro_export]
62macro_rules! chain_par {
63    () => {
64        rayon::iter::empty()
65    };
66    ($first:expr $(, $rest:expr )* $(,)?) => {
67        {
68            let iter = $crate::IntoParallelIterator::into_par_iter($first);
69            $(
70                let iter =
71                    ParallelIterator::chain(
72                        iter,
73                        $crate::IntoParallelIterator::into_par_iter($rest));
74            )*
75            iter
76        }
77    };
78}
79
80// found code for sum here: https://gist.github.com/jnordwick/1473d5533ca158d47ba4
81#[macro_export]
82macro_rules! sum {
83    ($h:expr) => ($h);              // so that this would be called, I ...
84    ($h:expr, $($t:expr),*) =>
85        (sum!($h) + sum!($($t),*)); // ...call sum! on both sides of the operation
86}