Function dptree::entry

source · []
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?
examples/simple_dispatcher.rs (line 34)
31
32
33
34
35
36
37
38
39
40
async fn main() {
    let store = Arc::new(AtomicI32::new(0));

    let dispatcher = dptree::entry()
        .branch(ping_handler())
        .branch(set_value_handler())
        .branch(print_value_handler());

    repl(dispatcher, store).await
}
More examples
Hide additional examples
examples/state_machine.rs (line 15)
12
13
14
15
16
17
18
19
20
21
22
async fn main() {
    let state = CommandState::Inactive;

    let dispatcher = dptree::entry()
        .branch(active_handler())
        .branch(paused_handler())
        .branch(inactive_handler())
        .branch(exit_handler());

    repl(state, dispatcher).await
}
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())
    );
}