mirror of
https://github.com/tokio-rs/axum.git
synced 2025-03-13 19:27:53 +01:00
Clean up constructors for future newtypes (#415)
This commit is contained in:
parent
68e44fa9da
commit
040f63b8e2
5 changed files with 17 additions and 21 deletions
|
@ -86,6 +86,7 @@ where
|
|||
type Error = Infallible;
|
||||
type Future = ResponseFuture<Self::Response>;
|
||||
|
||||
#[inline]
|
||||
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
Poll::Ready(Ok(()))
|
||||
}
|
||||
|
@ -93,9 +94,7 @@ where
|
|||
fn call(&mut self, target: T) -> Self::Future {
|
||||
let connect_info = ConnectInfo(C::connect_info(target));
|
||||
let svc = AddExtensionLayer::new(connect_info).layer(self.svc.clone());
|
||||
ResponseFuture {
|
||||
future: ready(Ok(svc)),
|
||||
}
|
||||
ResponseFuture::new(ready(Ok(svc)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -75,6 +75,6 @@ where
|
|||
let handler = self.handler.clone();
|
||||
let future = Handler::call(handler, req).map(Ok::<_, Infallible> as _);
|
||||
|
||||
super::future::IntoServiceFuture { future }
|
||||
super::future::IntoServiceFuture::new(future)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,13 @@ macro_rules! opaque_future {
|
|||
pin_project_lite::pin_project! {
|
||||
$(#[$m])*
|
||||
pub struct $name<$($param),*> {
|
||||
#[pin] pub(crate) future: $actual,
|
||||
#[pin] future: $actual,
|
||||
}
|
||||
}
|
||||
|
||||
impl<$($param),*> $name<$($param),*> {
|
||||
pub(crate) fn new(future: $actual) -> Self {
|
||||
Self { future }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
//! Future types.
|
||||
|
||||
use crate::body::BoxBody;
|
||||
use futures_util::future::Either;
|
||||
use http::{Request, Response};
|
||||
use pin_project_lite::pin_project;
|
||||
use std::{
|
||||
convert::Infallible,
|
||||
future::Future,
|
||||
future::{ready, Future},
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
|
@ -23,15 +24,11 @@ opaque_future! {
|
|||
|
||||
impl<B> RouterFuture<B> {
|
||||
pub(super) fn from_oneshot(future: Oneshot<super::Route<B>, Request<B>>) -> Self {
|
||||
Self {
|
||||
future: futures_util::future::Either::Left(future),
|
||||
}
|
||||
Self::new(Either::Left(future))
|
||||
}
|
||||
|
||||
pub(super) fn from_response(response: Response<BoxBody>) -> Self {
|
||||
RouterFuture {
|
||||
future: futures_util::future::Either::Right(std::future::ready(Ok(response))),
|
||||
}
|
||||
RouterFuture::new(Either::Right(ready(Ok(response))))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -928,9 +928,7 @@ where
|
|||
.body(crate::body::empty())
|
||||
.unwrap();
|
||||
|
||||
MethodNotAllowedFuture {
|
||||
future: ready(Ok(res)),
|
||||
}
|
||||
MethodNotAllowedFuture::new(ready(Ok(res)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1019,9 +1017,7 @@ where
|
|||
}
|
||||
|
||||
fn call(&mut self, _target: T) -> Self::Future {
|
||||
future::MakeRouteServiceFuture {
|
||||
future: ready(Ok(self.service.clone())),
|
||||
}
|
||||
future::MakeRouteServiceFuture::new(ready(Ok(self.service.clone())))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1054,9 +1050,7 @@ impl<B> Service<Request<B>> for Route<B> {
|
|||
|
||||
#[inline]
|
||||
fn call(&mut self, req: Request<B>) -> Self::Future {
|
||||
RouteFuture {
|
||||
future: self.0.call(req),
|
||||
}
|
||||
RouteFuture::new(self.0.call(req))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue