1use crate::response::Response;
4use axum_core::extract::Request;
5use futures_util::future::Map;
6use pin_project_lite::pin_project;
7use std::{convert::Infallible, future::Future, pin::Pin, task::Context};
8use tower::util::Oneshot;
9use tower_service::Service;
10
11opaque_future! {
12 pub type IntoServiceFuture<F> =
14 Map<
15 F,
16 fn(Response) -> Result<Response, Infallible>,
17 >;
18}
19
20pin_project! {
21 pub struct LayeredFuture<S>
23 where
24 S: Service<Request>,
25 {
26 #[pin]
27 inner: Map<Oneshot<S, Request>, fn(Result<S::Response, S::Error>) -> Response>,
28 }
29}
30
31impl<S> LayeredFuture<S>
32where
33 S: Service<Request>,
34{
35 pub(super) fn new(
36 inner: Map<Oneshot<S, Request>, fn(Result<S::Response, S::Error>) -> Response>,
37 ) -> Self {
38 Self { inner }
39 }
40}
41
42impl<S> Future for LayeredFuture<S>
43where
44 S: Service<Request>,
45{
46 type Output = Response;
47
48 #[inline]
49 fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> std::task::Poll<Self::Output> {
50 self.project().inner.poll(cx)
51 }
52}