sena 0.2.0

Library for composable event handlers
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use sena::{dependent::Dependent, handling::Handler};

#[derive(Debug, Clone)]
pub struct Delta(pub i32);

fn add<E>() -> impl Handler<Dependent<i32, Delta>, E, Output = i32> {
    |req: Dependent<i32, Delta>| async move { Ok(req.data + req.deps.0) }
}

#[tokio::main(flavor = "current_thread")]
async fn main() {
    let handler = add::<()>().provide(
        Delta(10),
        |env, req| async move { Ok(Dependent::new(req, env)) },
    );
    assert_eq!(handler.handle(10).await, Ok(20));
}