effectful 0.3.0

Effect<A, E, R> (sync + async), context/layers, pipe — interpreter-style, no bundled executor
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! Ex 027 — `Stack` composes layers into an HList.
use effectful::{Cons, LayerBuild, LayerFn, Nil, Service, Stack, Tagged};

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Service)]
struct AKey;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Service)]
struct BKey;

fn main() {
  let stack = Stack(
    LayerFn(|| Ok::<Tagged<AKey, u8>, ()>(Tagged::<AKey, _>::new(1_u8))),
    LayerFn(|| Ok::<Tagged<BKey, u16>, ()>(Tagged::<BKey, _>::new(2_u16))),
  );
  let Cons(a, Cons(b, Nil)) = stack.build().expect("stack");
  assert_eq!(a.value, 1);
  assert_eq!(b.value, 2);
  println!("027_stack_layers ok");
}