|
1 |
| -use std::fmt; |
2 |
| - |
3 |
| -/// A type map of protocol extensions. |
4 |
| -/// |
5 |
| -/// `Extensions` can be used by [`Interceptor`] and [`Request`] to store extra data derived from |
6 |
| -/// the underlying protocol. |
7 |
| -/// |
8 |
| -/// [`Interceptor`]: crate::service::Interceptor |
9 |
| -/// [`Request`]: crate::Request |
10 |
| -#[derive(Default)] |
11 |
| -pub struct Extensions { |
12 |
| - inner: http::Extensions, |
13 |
| -} |
14 |
| - |
15 |
| -impl Extensions { |
16 |
| - pub(crate) fn new() -> Self { |
17 |
| - Self { |
18 |
| - inner: http::Extensions::new(), |
19 |
| - } |
20 |
| - } |
21 |
| - |
22 |
| - /// Insert a type into this `Extensions`. |
23 |
| - /// |
24 |
| - /// If a extension of this type already existed, it will |
25 |
| - /// be returned. |
26 |
| - #[inline] |
27 |
| - pub fn insert<T: Clone + Send + Sync + 'static>(&mut self, val: T) -> Option<T> { |
28 |
| - self.inner.insert(val) |
29 |
| - } |
30 |
| - |
31 |
| - /// Get a reference to a type previously inserted on this `Extensions`. |
32 |
| - #[inline] |
33 |
| - pub fn get<T: Send + Sync + 'static>(&self) -> Option<&T> { |
34 |
| - self.inner.get() |
35 |
| - } |
36 |
| - |
37 |
| - /// Get a mutable reference to a type previously inserted on this `Extensions`. |
38 |
| - #[inline] |
39 |
| - pub fn get_mut<T: Send + Sync + 'static>(&mut self) -> Option<&mut T> { |
40 |
| - self.inner.get_mut() |
41 |
| - } |
42 |
| - |
43 |
| - /// Remove a type from this `Extensions`. |
44 |
| - /// |
45 |
| - /// If a extension of this type existed, it will be returned. |
46 |
| - #[inline] |
47 |
| - pub fn remove<T: Send + Sync + 'static>(&mut self) -> Option<T> { |
48 |
| - self.inner.remove() |
49 |
| - } |
50 |
| - |
51 |
| - /// Clear the `Extensions` of all inserted extensions. |
52 |
| - #[inline] |
53 |
| - pub fn clear(&mut self) { |
54 |
| - self.inner.clear() |
55 |
| - } |
56 |
| - |
57 |
| - #[inline] |
58 |
| - /// Convert from `http::Extensions` |
59 |
| - pub fn from_http(http: http::Extensions) -> Self { |
60 |
| - Self { inner: http } |
61 |
| - } |
62 |
| - |
63 |
| - /// Convert to `http::Extensions` and consume self. |
64 |
| - #[inline] |
65 |
| - pub fn into_http(self) -> http::Extensions { |
66 |
| - self.inner |
67 |
| - } |
68 |
| -} |
69 |
| - |
70 |
| -impl fmt::Debug for Extensions { |
71 |
| - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
72 |
| - f.debug_struct("Extensions").finish() |
73 |
| - } |
74 |
| -} |
75 |
| - |
76 | 1 | /// A gRPC Method info extension.
|
77 | 2 | #[derive(Debug, Clone)]
|
78 | 3 | pub struct GrpcMethod {
|
|
0 commit comments