macro_rules! delegate_handler {
    ($struct_name:ty) => { ... };
}
Expand description

Macro for implementing Handler for simple newtypes that contain another handler.

use trillium::{delegate_handler, State, Conn, conn_unwrap};
#[derive(Clone, Copy)]
struct MyState(usize);
struct MyHandler(State<MyState>);
delegate_handler!(MyHandler);
impl MyHandler {
    fn new(n: usize) -> Self {
        MyHandler(State::new(MyState(n)))
    }
}


let handler = (MyHandler::new(5), |conn: Conn| async move {
    let MyState(n) = *conn_unwrap!(conn.state(), conn);
    conn.ok(n.to_string())
});
assert_ok!(get("/").on(&handler), "5");