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
use super::hlist::push::PushBack;
use super::hlist::Nil;
mod start;
pub use start::SupSpecStartChild;
mod stop;
pub use stop::SupSpecStopChild;
#[derive(Debug)]
pub struct SupSpec<R, CS> {
pub restart_strategy: R,
pub children: CS,
}
impl<R> SupSpec<R, Nil> {
pub fn new(restart_strategy: R) -> Self {
Self { restart_strategy, children: Nil }
}
}
impl<R, CS> SupSpec<R, CS> {
pub fn with_child<C>(self, child: C) -> SupSpec<R, <CS as PushBack<C>>::Out>
where
CS: PushBack<C>,
{
let Self { restart_strategy, children } = self;
SupSpec { restart_strategy, children: children.push_back(child) }
}
}
#[cfg(test)]
mod tests {
use std::sync::Arc;
use agner_actors::Context;
use crate::fixed;
async fn behaviour_unit(_context: &mut Context<std::convert::Infallible>, _arg: ()) {
std::future::pending().await
}
async fn behaviour_arc_unit(_context: &mut Context<std::convert::Infallible>, _arg: Arc<()>) {
std::future::pending().await
}
#[test]
fn ergonomics() {
let restart_strategy = ();
let _sup_spec = fixed::SupSpec::new(restart_strategy)
.with_child(fixed::child_spec(behaviour_unit, fixed::arg_clone(())))
.with_child(fixed::child_spec(behaviour_arc_unit, fixed::arg_arc(())))
.with_child(fixed::child_spec(behaviour_unit, fixed::arg_call(|| ())));
}
}