diff --git a/core/lib/src/catcher.rs b/core/lib/src/catcher.rs index e39cf646..482702d2 100644 --- a/core/lib/src/catcher.rs +++ b/core/lib/src/catcher.rs @@ -154,7 +154,7 @@ macro_rules! default_catchers { let mut map = HashMap::new(); $( - fn $fn_name<'r>(req: &'r Request<'_>) -> std::pin::Pin> + Send + 'r>> { + fn $fn_name<'r>(req: &'r Request<'_>) -> futures::future::BoxFuture<'r, response::Result<'r>> { status::Custom(Status::from_code($code).unwrap(), content::Html(error_page_template!($code, $name, $description)) ).respond_to(req) diff --git a/core/lib/src/codegen.rs b/core/lib/src/codegen.rs index 894cf854..e61798e3 100644 --- a/core/lib/src/codegen.rs +++ b/core/lib/src/codegen.rs @@ -1,11 +1,11 @@ -use futures::future::Future; +use futures::future::BoxFuture; use crate::{Request, Data}; use crate::handler::{Outcome, ErrorHandler}; use crate::http::{Method, MediaType}; /// Type of a static handler, which users annotate with Rocket's attribute. -pub type StaticHandler = for<'r> fn(&'r Request<'_>, Data) -> std::pin::Pin> + Send + 'r>>; +pub type StaticHandler = for<'r> fn(&'r Request<'_>, Data) -> BoxFuture<'r, Outcome<'r>>; /// Information generated by the `route` attribute during codegen. pub struct StaticRouteInfo { diff --git a/core/lib/src/data/from_data.rs b/core/lib/src/data/from_data.rs index 90d76c5b..f9df6b99 100644 --- a/core/lib/src/data/from_data.rs +++ b/core/lib/src/data/from_data.rs @@ -1,7 +1,6 @@ use std::borrow::Borrow; -use std::pin::Pin; -use futures::future::{ready, Future, FutureExt}; +use futures::future::{ready, FutureExt, BoxFuture}; use futures::io::AsyncReadExt; use crate::outcome::{self, IntoOutcome}; @@ -112,8 +111,8 @@ pub type Transformed<'a, T> = Outcome<&'a >::Borrowed, >::Error> >; -pub type TransformFuture<'a, T, E> = Pin>> + Send + 'a>>; -pub type FromDataFuture<'a, T, E> = Pin> + Send + 'a>>; +pub type TransformFuture<'a, T, E> = BoxFuture<'a, Transform>>; +pub type FromDataFuture<'a, T, E> = BoxFuture<'a, Outcome>; /// Trait implemented by data guards to derive a value from request body data. /// diff --git a/core/lib/src/ext.rs b/core/lib/src/ext.rs index f7996e4f..d9da2f64 100644 --- a/core/lib/src/ext.rs +++ b/core/lib/src/ext.rs @@ -2,7 +2,7 @@ use std::io; use std::pin::Pin; use futures::io::{AsyncRead, AsyncReadExt as _}; -use futures::future::{Future}; +use futures::future::BoxFuture; use futures::stream::Stream; use futures::task::{Poll, Context}; @@ -73,7 +73,7 @@ pub trait AsyncReadExt: AsyncRead { } // TODO.async: Verify correctness of this implementation. - fn read_max<'a>(&'a mut self, mut buf: &'a mut [u8]) -> Pin> + Send + '_>> + fn read_max<'a>(&'a mut self, mut buf: &'a mut [u8]) -> BoxFuture<'_, io::Result> where Self: Send + Unpin { Box::pin(async move { diff --git a/core/lib/src/fairing/ad_hoc.rs b/core/lib/src/fairing/ad_hoc.rs index eb4596d4..bb666e52 100644 --- a/core/lib/src/fairing/ad_hoc.rs +++ b/core/lib/src/fairing/ad_hoc.rs @@ -1,7 +1,7 @@ -use std::future::Future; -use std::pin::Pin; use std::sync::Mutex; +use futures::future::BoxFuture; + use crate::{Rocket, Request, Response, Data}; use crate::fairing::{Fairing, Kind, Info}; @@ -51,7 +51,7 @@ enum AdHocKind { Request(Box, &Data) + Send + Sync + 'static>), /// An ad-hoc **response** fairing. Called when a response is ready to be /// sent to a client. - Response(Box Fn(&'a Request<'r>, &'a mut Response<'r>) -> Pin + Send + 'a>> + Send + Sync + 'static>), + Response(Box Fn(&'a Request<'r>, &'a mut Response<'r>) -> BoxFuture<'a, ()> + Send + Sync + 'static>), } impl AdHoc { @@ -128,7 +128,7 @@ impl AdHoc { /// }); /// ``` pub fn on_response(name: &'static str, f: F) -> AdHoc - where F: for<'a, 'r> Fn(&'a Request<'r>, &'a mut Response<'r>) -> Pin + Send + 'a>> + Send + Sync + 'static + where F: for<'a, 'r> Fn(&'a Request<'r>, &'a mut Response<'r>) -> BoxFuture<'a, ()> + Send + Sync + 'static { AdHoc { name, kind: AdHocKind::Response(Box::new(f)) } } @@ -170,7 +170,7 @@ impl Fairing for AdHoc { } } - fn on_response<'a, 'r>(&'a self, request: &'a Request<'r>, response: &'a mut Response<'r>) -> Pin + Send + 'a>> { + fn on_response<'a, 'r>(&'a self, request: &'a Request<'r>, response: &'a mut Response<'r>) -> BoxFuture<'a, ()> { if let AdHocKind::Response(ref callback) = self.kind { callback(request, response) } else { diff --git a/core/lib/src/fairing/mod.rs b/core/lib/src/fairing/mod.rs index 717db7d7..ddc1030f 100644 --- a/core/lib/src/fairing/mod.rs +++ b/core/lib/src/fairing/mod.rs @@ -47,8 +47,7 @@ //! of other `Fairings` are not jeopardized. For instance, unless it is made //! abundantly clear, a fairing should not rewrite every request. -use std::pin::Pin; -use std::future::Future; +use futures::future::BoxFuture; use crate::{Rocket, Request, Response, Data}; @@ -419,7 +418,7 @@ pub trait Fairing: Send + Sync + 'static { /// /// The default implementation of this method does nothing. #[allow(unused_variables)] - fn on_response<'a, 'r>(&'a self, request: &'a Request<'r>, response: &'a mut Response<'r>) -> Pin + Send + 'a>> { + fn on_response<'a, 'r>(&'a self, request: &'a Request<'r>, response: &'a mut Response<'r>) -> BoxFuture<'a, ()> { Box::pin(async { }) } } @@ -446,7 +445,7 @@ impl Fairing for std::sync::Arc { } #[inline] - fn on_response<'a, 'r>(&'a self, request: &'a Request<'r>, response: &'a mut Response<'r>) -> Pin + Send + 'a>> { + fn on_response<'a, 'r>(&'a self, request: &'a Request<'r>, response: &'a mut Response<'r>) -> BoxFuture<'a, ()> { (self as &T).on_response(request, response) } } diff --git a/core/lib/src/handler.rs b/core/lib/src/handler.rs index 5d7df23e..96791d7a 100644 --- a/core/lib/src/handler.rs +++ b/core/lib/src/handler.rs @@ -1,6 +1,6 @@ //! Types and traits for request and error handlers and their return values. -use futures::future::Future; +use futures::future::BoxFuture; use crate::data::Data; use crate::request::Request; @@ -12,7 +12,7 @@ use crate::outcome; pub type Outcome<'r> = outcome::Outcome, Status, Data>; /// Type alias for the unwieldy `Handler` return type -pub type HandlerFuture<'r> = std::pin::Pin> + Send + 'r>>; +pub type HandlerFuture<'r> = BoxFuture<'r, Outcome<'r>>; /// Trait implemented by types that can handle requests. /// @@ -186,7 +186,7 @@ impl Handler for F /// The type of an error handler. pub type ErrorHandler = for<'r> fn(&'r Request<'_>) -> ErrorHandlerFuture<'r>; -pub type ErrorHandlerFuture<'r> = std::pin::Pin> + Send + 'r>>; +pub type ErrorHandlerFuture<'r> = BoxFuture<'r, response::Result<'r>>; impl<'r> Outcome<'r> { /// Return the `Outcome` of response to `req` from `responder`. diff --git a/core/lib/src/response/mod.rs b/core/lib/src/response/mod.rs index e77e585f..d179a09c 100644 --- a/core/lib/src/response/mod.rs +++ b/core/lib/src/response/mod.rs @@ -49,4 +49,4 @@ pub use self::debug::Debug; /// Type alias for the `Result` of a `Responder::respond` call. pub type Result<'r> = std::result::Result, crate::http::Status>; /// Type alias for the `Result` of a `Responder::respond` call. -pub type ResultFuture<'r> = std::pin::Pin> + Send + 'r>>; +pub type ResultFuture<'r> = futures::future::BoxFuture<'r, Result<'r>>; diff --git a/core/lib/src/rocket.rs b/core/lib/src/rocket.rs index 218fe209..793c03b6 100644 --- a/core/lib/src/rocket.rs +++ b/core/lib/src/rocket.rs @@ -6,9 +6,8 @@ use std::mem; use std::net::ToSocketAddrs; use std::sync::Arc; use std::time::Duration; -use std::pin::Pin; -use futures::future::{Future, FutureExt, TryFutureExt}; +use futures::future::{Future, FutureExt, TryFutureExt, BoxFuture}; use futures::stream::StreamExt; use futures::task::SpawnExt; use futures_tokio_compat::Compat as TokioCompat; @@ -256,7 +255,7 @@ impl Rocket { request._set_method(Method::Get); // Return early so we don't set cookies twice. - let try_next: Pin + Send>> = Box::pin(self.route_and_process(request, data)); + let try_next: BoxFuture<'_, _> = Box::pin(self.route_and_process(request, data)); return try_next.await; } else { // No match was found and it can't be autohandled. 404. diff --git a/core/lib/src/router/mod.rs b/core/lib/src/router/mod.rs index edf25b70..6ad00a4e 100644 --- a/core/lib/src/router/mod.rs +++ b/core/lib/src/router/mod.rs @@ -3,7 +3,7 @@ mod route; use std::collections::hash_map::HashMap; -use futures::future::Future; +use futures::future::BoxFuture; pub use self::route::Route; @@ -14,7 +14,7 @@ use crate::http::Method; type Selector = Method; // A handler to use when one is needed temporarily. -pub(crate) fn dummy_handler<'r>(r: &'r Request<'_>, _: crate::Data) -> std::pin::Pin> + Send + 'r>> { +pub(crate) fn dummy_handler<'r>(r: &'r Request<'_>, _: crate::Data) -> BoxFuture<'r, crate::handler::Outcome<'r>> { crate::Outcome::from(r, ()) }