/rust/registry/src/index.crates.io-1949cf8c6b5b557f/tower-http-0.6.10/src/macros.rs
Line | Count | Source |
1 | | #[allow(unused_macros)] |
2 | | macro_rules! define_inner_service_accessors { |
3 | | () => { |
4 | | /// Gets a reference to the underlying service. |
5 | 0 | pub fn get_ref(&self) -> &S { |
6 | 0 | &self.inner |
7 | 0 | } |
8 | | |
9 | | /// Gets a mutable reference to the underlying service. |
10 | 0 | pub fn get_mut(&mut self) -> &mut S { |
11 | 0 | &mut self.inner |
12 | 0 | } |
13 | | |
14 | | /// Consumes `self`, returning the underlying service. |
15 | 0 | pub fn into_inner(self) -> S { |
16 | 0 | self.inner |
17 | 0 | } |
18 | | }; |
19 | | } |
20 | | |
21 | | #[allow(unused_macros)] |
22 | | macro_rules! opaque_body { |
23 | | ($(#[$m:meta])* pub type $name:ident = $actual:ty;) => { |
24 | | opaque_body! { |
25 | | $(#[$m])* pub type $name<> = $actual; |
26 | | } |
27 | | }; |
28 | | |
29 | | ($(#[$m:meta])* pub type $name:ident<$($param:ident),*> = $actual:ty;) => { |
30 | | pin_project_lite::pin_project! { |
31 | | $(#[$m])* |
32 | | pub struct $name<$($param),*> { |
33 | | #[pin] |
34 | | pub(crate) inner: $actual |
35 | | } |
36 | | } |
37 | | |
38 | | impl<$($param),*> $name<$($param),*> { |
39 | | pub(crate) fn new(inner: $actual) -> Self { |
40 | | Self { inner } |
41 | | } |
42 | | } |
43 | | |
44 | | impl<$($param),*> http_body::Body for $name<$($param),*> { |
45 | | type Data = <$actual as http_body::Body>::Data; |
46 | | type Error = <$actual as http_body::Body>::Error; |
47 | | |
48 | | #[inline] |
49 | | fn poll_frame( |
50 | | self: std::pin::Pin<&mut Self>, |
51 | | cx: &mut std::task::Context<'_>, |
52 | | ) -> std::task::Poll<Option<Result<http_body::Frame<Self::Data>, Self::Error>>> { |
53 | | self.project().inner.poll_frame(cx) |
54 | | } |
55 | | |
56 | | #[inline] |
57 | | fn is_end_stream(&self) -> bool { |
58 | | http_body::Body::is_end_stream(&self.inner) |
59 | | } |
60 | | |
61 | | #[inline] |
62 | | fn size_hint(&self) -> http_body::SizeHint { |
63 | | http_body::Body::size_hint(&self.inner) |
64 | | } |
65 | | } |
66 | | }; |
67 | | } |
68 | | |
69 | | #[allow(unused_macros)] |
70 | | macro_rules! opaque_future { |
71 | | ($(#[$m:meta])* pub type $name:ident<$($param:ident),+> = $actual:ty;) => { |
72 | | pin_project_lite::pin_project! { |
73 | | $(#[$m])* |
74 | | pub struct $name<$($param),+> { |
75 | | #[pin] |
76 | | inner: $actual |
77 | | } |
78 | | } |
79 | | |
80 | | impl<$($param),+> $name<$($param),+> { |
81 | | pub(crate) fn new(inner: $actual) -> Self { |
82 | | Self { |
83 | | inner |
84 | | } |
85 | | } |
86 | | } |
87 | | |
88 | | impl<$($param),+> std::fmt::Debug for $name<$($param),+> { |
89 | | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
90 | | f.debug_tuple(stringify!($name)).field(&format_args!("...")).finish() |
91 | | } |
92 | | } |
93 | | |
94 | | impl<$($param),+> std::future::Future for $name<$($param),+> |
95 | | where |
96 | | $actual: std::future::Future, |
97 | | { |
98 | | type Output = <$actual as std::future::Future>::Output; |
99 | | #[inline] |
100 | | fn poll(self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> std::task::Poll<Self::Output> { |
101 | | self.project().inner.poll(cx) |
102 | | } |
103 | | } |
104 | | } |
105 | | } |