ntex_service/
macros.rs

1/// An implementation of [`crate::Service::ready`] that forwards readiness checks to a field.
2#[macro_export]
3macro_rules! forward_ready {
4    ($field:ident) => {
5        #[inline]
6        async fn ready(
7            &self,
8            ctx: $crate::ServiceCtx<'_, Self>,
9        ) -> Result<(), Self::Error> {
10            ctx.ready(&self.$field)
11                .await
12                .map_err(::core::convert::Into::into)
13        }
14    };
15    ($field:ident, $err:expr) => {
16        #[inline]
17        async fn ready(
18            &self,
19            ctx: $crate::ServiceCtx<'_, Self>,
20        ) -> Result<(), Self::Error> {
21            ctx.ready(&self.$field).await.map_err($err)
22        }
23    };
24}
25
26/// An implementation of [`crate::Service::poll`] that forwards poll call to a field.
27#[macro_export]
28macro_rules! forward_poll {
29    ($field:ident) => {
30        #[inline]
31        fn poll(&self, cx: &mut std::task::Context<'_>) -> Result<(), Self::Error> {
32            self.$field.poll(cx).map_err(From::from)
33        }
34    };
35    ($field:ident, $err:expr) => {
36        #[inline]
37        fn poll(&self, cx: &mut std::task::Context<'_>) -> Result<(), Self::Error> {
38            self.$field.poll(cx).map_err($err)
39        }
40    };
41}
42
43/// An implementation of [`crate::Service::shutdown`] that forwards shutdown checks to a field.
44#[macro_export]
45macro_rules! forward_shutdown {
46    ($field:ident) => {
47        #[inline]
48        async fn shutdown(&self) {
49            self.$field.shutdown().await
50        }
51    };
52}