1use std::fmt;
2
3pub struct Extensions {
11 inner: http::Extensions,
12}
13
14impl Extensions {
15 pub(crate) fn new() -> Self {
16 Self {
17 inner: http::Extensions::new(),
18 }
19 }
20
21 #[inline]
26 pub fn insert<T: Send + Sync + 'static>(&mut self, val: T) -> Option<T> {
27 self.inner.insert(val)
28 }
29
30 #[inline]
32 pub fn get<T: Send + Sync + 'static>(&self) -> Option<&T> {
33 self.inner.get()
34 }
35
36 #[inline]
38 pub fn get_mut<T: Send + Sync + 'static>(&mut self) -> Option<&mut T> {
39 self.inner.get_mut()
40 }
41
42 #[inline]
46 pub fn remove<T: Send + Sync + 'static>(&mut self) -> Option<T> {
47 self.inner.remove()
48 }
49
50 #[inline]
52 pub fn clear(&mut self) {
53 self.inner.clear()
54 }
55
56 #[inline]
57 pub(crate) fn from_http(http: http::Extensions) -> Self {
58 Self { inner: http }
59 }
60
61 #[inline]
62 pub(crate) fn into_http(self) -> http::Extensions {
63 self.inner
64 }
65}
66
67impl fmt::Debug for Extensions {
68 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
69 f.debug_struct("Extensions").finish()
70 }
71}