pub fn entry<'a, Input, Output, Descr>() -> Handler<'a, Input, Output, Descr> where
Input: Send + 'a,
Output: 'a,
Descr: HandlerDescription,
Expand description
Constructs an entry point handler.
This function is only used to specify other handlers upon it (see the root examples).
Examples found in repository?
More examples
examples/descr_locations.rs (line 95)
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
fn main() {
#[rustfmt::skip]
let some_tree: Handler<DependencyMap, _, _> = dptree::entry()
.branch(
dptree::filter(|| true)
.endpoint(|| async {})
)
.branch(
dptree::filter_async(|| async { true })
.chain(dptree::filter_map(|| Some(1) ))
.endpoint(|| async {})
);
get_locations(&some_tree).iter().for_each(|(name, loc)| println!("{name: <12} @ {loc}"));
}
examples/web_server.rs (line 8)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
async fn main() {
let web_server = dptree::entry()
.branch(smiles_handler())
.branch(sqrt_handler())
.branch(not_found_handler());
assert_eq!(
web_server.dispatch(dptree::deps!["/smile"]).await,
ControlFlow::Break("🙃".to_owned())
);
assert_eq!(
web_server.dispatch(dptree::deps!["/sqrt 16"]).await,
ControlFlow::Break("4".to_owned())
);
assert_eq!(
web_server.dispatch(dptree::deps!["/lol"]).await,
ControlFlow::Break("404 Not Found".to_owned())
);
}