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