macro_rules! router {
(|$state:ident| async move $body:block) => { ... };
(|$state:ident, $config:ident| async move $body:block) => { ... };
}Expand description
Helper macro to create a router from an async closure.
§Forms
ⓘ
// Basic form (backward compatible) - body returns Result<Option<String>>
router!(|state| async move {
let value: i32 = state.get("value").await?;
Ok(if value > 5 { Some("high".to_string()) } else { None })
})
// With config - body returns Result<impl Into<RouterOutput>>
router!(|state, config| async move {
let value: i32 = state.get("value").await?;
Ok(RouterOutput::FanOut(vec!["a".to_string(), "b".to_string()]))
})