Macro trillium::conn_unwrap [−][src]
macro_rules! conn_unwrap { ($conn:expr, $option:expr) => { ... }; }
Expand description
Unwraps an Option::Some or returns the conn.
This is useful for gracefully exiting a Handler without returning an error.
use trillium_testing::prelude::*; use trillium::{Conn, conn_unwrap, State}; #[derive(Copy, Clone)] struct MyState(&'static str); let handler = |conn: trillium::Conn| async move { let important_state: MyState = *conn_unwrap!(conn, conn.state()); conn.ok(important_state.0) }; assert_not_handled!(get("/").on(&handler)); // we never reached the conn.ok line. assert_ok!( get("/").on(&(State::new(MyState("hi")), handler)), "hi" );