use std::{ convert::Infallible, future::ready, task::{Context, Poll}, }; use tower_service::Service; /// A [`MakeService`] that produces axum router services. /// /// [`MakeService`]: tower::make::MakeService #[derive(Debug, Clone)] pub struct IntoMakeService { svc: S, } impl IntoMakeService { pub(crate) fn new(svc: S) -> Self { Self { svc } } } impl Service for IntoMakeService where S: Clone, { type Response = S; type Error = Infallible; type Future = IntoMakeServiceFuture; #[inline] fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) } fn call(&mut self, _target: T) -> Self::Future { IntoMakeServiceFuture::new(ready(Ok(self.svc.clone()))) } } opaque_future! { /// Response future for [`IntoMakeService`]. pub type IntoMakeServiceFuture = std::future::Ready>; } #[cfg(test)] mod tests { use super::*; use crate::body::Body; #[test] fn traits() { use crate::test_helpers::*; assert_send::>(); } }