1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
mod all_storages;
pub use all_storages::AllSystem;
use crate::borrow::{Borrow, IntoBorrow};
use crate::error;
use crate::world::World;
pub struct Nothing;
pub trait System<'s, Data, Borrow, Return> {
#[allow(missing_docs)]
fn run(self, data: Data, world: &'s World) -> Result<Return, error::GetStorage>;
}
impl<'s, Return, F> System<'s, (), Nothing, Return> for F
where
F: FnOnce() -> Return,
{
fn run(self, _: (), _: &'s World) -> Result<Return, error::GetStorage> {
Ok((self)())
}
}
impl<'s, Data, Return, F> System<'s, (Data,), Nothing, Return> for F
where
F: FnOnce(Data) -> Return,
{
fn run(self, (data,): (Data,), _: &'s World) -> Result<Return, error::GetStorage> {
Ok((self)(data))
}
}
macro_rules! impl_system {
($(($type: ident, $index: tt))+) => {
impl<'s, $($type: IntoBorrow,)+ Return, Func> System<'s, (), ($($type,)+), Return> for Func
where
Func: FnOnce($($type),+) -> Return
+ FnOnce($(<$type::Borrow as Borrow<'s>>::View),+) -> Return
{
fn run(self, _: (), world: &'s World) -> Result<Return, error::GetStorage> {
let current = world.get_current();
Ok((self)($($type::Borrow::borrow(world, None, current)?,)+))
}
}
impl<'s, Data, $($type: IntoBorrow,)+ Return, Func> System<'s, (Data,), ($($type,)+), Return> for Func
where
Func: FnOnce(Data, $($type),+) -> Return
+ FnOnce(Data, $(<$type::Borrow as Borrow<'s>>::View),+) -> Return
{
fn run(self, (data,): (Data,), world: &'s World) -> Result<Return, error::GetStorage> {
let current = world.get_current();
Ok((self)(data, $($type::Borrow::borrow(world, None, current)?,)+))
}
}
}
}
macro_rules! system {
($(($type: ident, $index: tt))*;($type1: ident, $index1: tt) $(($queue_type: ident, $queue_index: tt))*) => {
impl_system![$(($type, $index))*];
system![$(($type, $index))* ($type1, $index1); $(($queue_type, $queue_index))*];
};
($(($type: ident, $index: tt))*;) => {
impl_system![$(($type, $index))*];
}
}
system![(A, 0); (B, 1) (C, 2) (D, 3) (E, 4) (F, 5) (G, 6) (H, 7) (I, 8) (J, 9)];