mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-25 00:00:23 +02:00
Improve compile times (#184)
* Inline `handler::IntoService` * Inline `BoxResponseBody` * Add missing debug impl
This commit is contained in:
+18
-30
@@ -3,6 +3,7 @@
|
||||
use crate::{
|
||||
body::{box_body, BoxBody},
|
||||
response::IntoResponse,
|
||||
util::{Either, EitherProj},
|
||||
};
|
||||
use bytes::Bytes;
|
||||
use futures_util::ready;
|
||||
@@ -14,7 +15,7 @@ use std::{
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
use tower::{BoxError, Service};
|
||||
use tower::{util::Oneshot, BoxError, Service};
|
||||
|
||||
pin_project! {
|
||||
/// Response future for [`HandleError`](super::HandleError).
|
||||
@@ -52,54 +53,41 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
/// Response future for [`BoxResponseBody`].
|
||||
#[derive(Debug)]
|
||||
pub struct BoxResponseBodyFuture<F> {
|
||||
#[pin]
|
||||
pub(super) future: F,
|
||||
}
|
||||
}
|
||||
|
||||
impl<F, B, E> Future for BoxResponseBodyFuture<F>
|
||||
where
|
||||
F: Future<Output = Result<Response<B>, E>>,
|
||||
B: http_body::Body<Data = Bytes> + Send + Sync + 'static,
|
||||
B::Error: Into<BoxError> + Send + Sync + 'static,
|
||||
{
|
||||
type Output = Result<Response<BoxBody>, E>;
|
||||
|
||||
fn poll(self: std::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let res = ready!(self.project().future.poll(cx))?;
|
||||
let res = res.map(box_body);
|
||||
Poll::Ready(Ok(res))
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
/// The response future for [`OnMethod`](super::OnMethod).
|
||||
#[derive(Debug)]
|
||||
pub struct OnMethodFuture<S, F, B>
|
||||
where
|
||||
S: Service<Request<B>>,
|
||||
F: Service<Request<B>>
|
||||
{
|
||||
#[pin]
|
||||
pub(super) inner: crate::routing::future::RouteFuture<S, F, B>,
|
||||
pub(super) inner: Either<
|
||||
Oneshot<S, Request<B>>,
|
||||
Oneshot<F, Request<B>>,
|
||||
>,
|
||||
// pub(super) inner: crate::routing::future::RouteFuture<S, F, B>,
|
||||
pub(super) req_method: Method,
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, F, B> Future for OnMethodFuture<S, F, B>
|
||||
impl<S, F, B, ResBody> Future for OnMethodFuture<S, F, B>
|
||||
where
|
||||
S: Service<Request<B>, Response = Response<BoxBody>>,
|
||||
S: Service<Request<B>, Response = Response<ResBody>> + Clone,
|
||||
ResBody: http_body::Body<Data = Bytes> + Send + Sync + 'static,
|
||||
ResBody::Error: Into<BoxError>,
|
||||
F: Service<Request<B>, Response = Response<BoxBody>, Error = S::Error>,
|
||||
{
|
||||
type Output = Result<Response<BoxBody>, S::Error>;
|
||||
|
||||
#[allow(warnings)]
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let this = self.project();
|
||||
let response = futures_util::ready!(this.inner.poll(cx))?;
|
||||
|
||||
let response = match this.inner.project() {
|
||||
EitherProj::A { inner } => ready!(inner.poll(cx))?.map(box_body),
|
||||
EitherProj::B { inner } => ready!(inner.poll(cx))?,
|
||||
};
|
||||
|
||||
if this.req_method == &Method::HEAD {
|
||||
let response = response.map(|_| box_body(Empty::new()));
|
||||
Poll::Ready(Ok(response))
|
||||
|
||||
Reference in New Issue
Block a user