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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
mod reflect;
use hyper::http::Extensions;
pub use reflect::*;
mod gateway_name;
pub use gateway_name::*;
mod matched;
pub use matched::*;
mod peer_addr;
pub use peer_addr::*;
mod backend_host;
pub use backend_host::*;
mod enter_time;
pub use enter_time::*;
mod request_id;
/// FromBackend is a marker type to indicate that the response is from backend.
#[derive(Debug, Clone, Copy)]
pub struct FromBackend {
    _priv: (),
}

impl FromBackend {
    /// # Safety
    ///
    /// **Ensure** the response is from the **real backend**, do not cheat on users of this type.
    pub const unsafe fn new() -> Self {
        Self { _priv: () }
    }
}

pub trait ExtensionPack: Sized {
    fn insert(self, ext: &mut Extensions) -> Option<Self>
    where
        Self: Clone + Send + Sync + 'static,
    {
        ext.insert::<Self>(self)
    }

    fn get(ext: &Extensions) -> Option<&Self>
    where
        Self: Send + Sync + 'static,
    {
        ext.get::<Self>()
    }

    fn get_mut(ext: &mut Extensions) -> Option<&mut Self>
    where
        Self: Send + Sync + 'static,
    {
        ext.get_mut::<Self>()
    }

    fn remove(ext: &mut Extensions) -> Option<Self>
    where
        Self: Send + Sync + 'static,
    {
        ext.remove::<Self>()
    }
}