1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use dptree::prelude::*;
use std::{net::Ipv4Addr, sync::Arc};
type Store = Arc<DependencyMap>;
#[tokio::main]
async fn main() {
fn assert_num_string_handler(
expected_num: u32,
expected_string: &'static str,
) -> Endpoint<'static, Store, ()> {
dptree::endpoint(move |num: u32, string: String| async move {
assert_eq!(num, expected_num);
assert_eq!(string, expected_string);
})
}
let store = Arc::new(dptree::deps![10u32, "Hello".to_owned()]);
let str_num_handler = assert_num_string_handler(10u32, "Hello");
str_num_handler.dispatch(store.clone()).await;
let handle = tokio::spawn(async move {
let ip_handler: Endpoint<_, _> = dptree::endpoint(|ip: Ipv4Addr| async move {
assert_eq!(ip, Ipv4Addr::new(0, 0, 0, 0));
});
ip_handler.dispatch(store.clone()).await;
});
let result = handle.await;
assert!(result.is_err())
}