Clean up constructors for future newtypes (#415)

This commit is contained in:
David Pedersen
2021-10-25 23:03:16 +00:00
committed by GitHub
parent 68e44fa9da
commit 040f63b8e2
5 changed files with 17 additions and 21 deletions
+4 -7
View File
@@ -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
View File
@@ -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))
}
}