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
36
use std::convert::Infallible;
use futures::future;
use crate::filter::{filter_fn_one, Filter};
use crate::reject::{self, Rejection};
pub fn get<T: Clone + Send + Sync + 'static>(
) -> impl Filter<Extract = (T,), Error = Rejection> + Copy {
filter_fn_one(|route| {
let route = route
.extensions()
.get::<T>()
.cloned()
.ok_or_else(|| reject::known(MissingExtension { _p: () }));
future::ready(route)
})
}
pub fn optional<T: Clone + Send + Sync + 'static>(
) -> impl Filter<Extract = (Option<T>,), Error = Infallible> + Copy {
filter_fn_one(|route| future::ok(route.extensions().get::<T>().cloned()))
}
unit_error! {
pub MissingExtension: "Missing request extension"
}