1 use std::{
2     convert::Infallible,
3     future::ready,
4     task::{Context, Poll},
5 };
6 use tower_service::Service;
7 
8 /// A [`MakeService`] that produces axum router services.
9 ///
10 /// [`MakeService`]: tower::make::MakeService
11 #[derive(Debug, Clone)]
12 pub struct IntoMakeService<S> {
13     svc: S,
14 }
15 
16 impl<S> IntoMakeService<S> {
new(svc: S) -> Self17     pub(crate) fn new(svc: S) -> Self {
18         Self { svc }
19     }
20 }
21 
22 impl<S, T> Service<T> for IntoMakeService<S>
23 where
24     S: Clone,
25 {
26     type Response = S;
27     type Error = Infallible;
28     type Future = IntoMakeServiceFuture<S>;
29 
30     #[inline]
poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>31     fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
32         Poll::Ready(Ok(()))
33     }
34 
call(&mut self, _target: T) -> Self::Future35     fn call(&mut self, _target: T) -> Self::Future {
36         IntoMakeServiceFuture::new(ready(Ok(self.svc.clone())))
37     }
38 }
39 
40 opaque_future! {
41     /// Response future for [`IntoMakeService`].
42     pub type IntoMakeServiceFuture<S> =
43         std::future::Ready<Result<S, Infallible>>;
44 }
45 
46 #[cfg(test)]
47 mod tests {
48     use super::*;
49     use crate::body::Body;
50 
51     #[test]
traits()52     fn traits() {
53         use crate::test_helpers::*;
54 
55         assert_send::<IntoMakeService<Body>>();
56     }
57 }
58