mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-31 00:00:10 +02:00
Clean up constructors for future newtypes (#415)
This commit is contained in:
@@ -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))))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-9
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user