diff --git a/contrib/lib/src/databases.rs b/contrib/lib/src/databases.rs index 64a9e3f5..1d8000d2 100644 --- a/contrib/lib/src/databases.rs +++ b/contrib/lib/src/databases.rs @@ -50,7 +50,7 @@ //! In your application's source code, one-time: //! //! ```rust -//! #![feature(proc_macro_hygiene)] +//! #![feature(proc_macro_hygiene, async_await)] //! //! #[macro_use] extern crate rocket; //! #[macro_use] extern crate rocket_contrib; diff --git a/contrib/lib/src/uuid.rs b/contrib/lib/src/uuid.rs index 5fab5efd..dd86a7ff 100644 --- a/contrib/lib/src/uuid.rs +++ b/contrib/lib/src/uuid.rs @@ -42,7 +42,7 @@ pub use self::uuid_crate::parser::ParseError; /// You can use the `Uuid` type directly as a target of a dynamic parameter: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # #[macro_use] extern crate rocket_contrib; /// use rocket_contrib::uuid::Uuid; @@ -56,7 +56,7 @@ pub use self::uuid_crate::parser::ParseError; /// You can also use the `Uuid` as a form value, including in query strings: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # #[macro_use] extern crate rocket_contrib; /// use rocket_contrib::uuid::Uuid; diff --git a/contrib/lib/tests/compress_responder.rs b/contrib/lib/tests/compress_responder.rs index 2d317ddf..fdef99c0 100644 --- a/contrib/lib/tests/compress_responder.rs +++ b/contrib/lib/tests/compress_responder.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] #[macro_use] #[cfg(all(feature = "brotli_compression", feature = "gzip_compression"))] diff --git a/contrib/lib/tests/compression_fairing.rs b/contrib/lib/tests/compression_fairing.rs index fa09188d..491957a9 100644 --- a/contrib/lib/tests/compression_fairing.rs +++ b/contrib/lib/tests/compression_fairing.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] #[macro_use] #[cfg(all(feature = "brotli_compression", feature = "gzip_compression"))] diff --git a/core/codegen/src/lib.rs b/core/codegen/src/lib.rs index db72073b..7287cc8c 100644 --- a/core/codegen/src/lib.rs +++ b/core/codegen/src/lib.rs @@ -30,7 +30,7 @@ //! crate root: //! //! ```rust -//! #![feature(proc_macro_hygiene)] +//! #![feature(proc_macro_hygiene, async_await)] //! //! #[macro_use] extern crate rocket; //! # #[get("/")] fn hello() { } @@ -40,7 +40,7 @@ //! Or, alternatively, selectively import from the top-level scope: //! //! ```rust -//! #![feature(proc_macro_hygiene)] +//! #![feature(proc_macro_hygiene, async_await)] //! # extern crate rocket; //! //! use rocket::{get, routes}; @@ -147,7 +147,7 @@ macro_rules! route_attribute { /// functions: /// /// ```rust - /// # #![feature(proc_macro_hygiene)] + /// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # /// #[get("/")] @@ -170,7 +170,7 @@ macro_rules! route_attribute { /// explicitly specified: /// /// ```rust - /// # #![feature(proc_macro_hygiene)] + /// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # /// #[route(GET, path = "/")] @@ -231,7 +231,7 @@ macro_rules! route_attribute { /// the arguments `foo`, `baz`, `msg`, `rest`, and `form`: /// /// ```rust - /// # #![feature(proc_macro_hygiene)] + /// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # use rocket::request::Form; /// # use std::path::PathBuf; @@ -343,7 +343,7 @@ route_attribute!(options => Method::Options); /// This attribute can only be applied to free functions: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # /// use rocket::Request; @@ -755,7 +755,7 @@ pub fn derive_uri_display_path(input: TokenStream) -> TokenStream { /// corresponding [`Route`] structures. For example, given the following routes: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # /// #[get("/")] @@ -770,7 +770,7 @@ pub fn derive_uri_display_path(input: TokenStream) -> TokenStream { /// The `routes!` macro can be used as: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # /// # use rocket::http::Method; @@ -814,7 +814,7 @@ pub fn routes(input: TokenStream) -> TokenStream { /// catchers: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # /// #[catch(404)] @@ -829,7 +829,7 @@ pub fn routes(input: TokenStream) -> TokenStream { /// The `catchers!` macro can be used as: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # /// # #[catch(404)] fn not_found() { /* .. */ } @@ -871,7 +871,7 @@ pub fn catchers(input: TokenStream) -> TokenStream { /// For example, for the following route: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # /// #[get("/person/?")] @@ -885,7 +885,7 @@ pub fn catchers(input: TokenStream) -> TokenStream { /// A URI can be created as follows: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # /// # #[get("/person/?")] diff --git a/core/codegen/tests/expansion.rs b/core/codegen/tests/expansion.rs index aaaf2fcd..d5d4f00e 100644 --- a/core/codegen/tests/expansion.rs +++ b/core/codegen/tests/expansion.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] #[macro_use] extern crate rocket; diff --git a/core/codegen/tests/responder.rs b/core/codegen/tests/responder.rs index 0df09bc6..9608faf0 100644 --- a/core/codegen/tests/responder.rs +++ b/core/codegen/tests/responder.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] use rocket::local::Client; use rocket::response::Responder; diff --git a/core/codegen/tests/route-data.rs b/core/codegen/tests/route-data.rs index e15f4bb5..8a9cbc6f 100644 --- a/core/codegen/tests/route-data.rs +++ b/core/codegen/tests/route-data.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] #[macro_use] extern crate rocket; diff --git a/core/codegen/tests/route-format.rs b/core/codegen/tests/route-format.rs index 32bb935c..d29e77cb 100644 --- a/core/codegen/tests/route-format.rs +++ b/core/codegen/tests/route-format.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] #[macro_use] extern crate rocket; diff --git a/core/codegen/tests/route-ranking.rs b/core/codegen/tests/route-ranking.rs index a85ee24c..5fcc364b 100644 --- a/core/codegen/tests/route-ranking.rs +++ b/core/codegen/tests/route-ranking.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] #[macro_use] extern crate rocket; diff --git a/core/codegen/tests/typed-uris.rs b/core/codegen/tests/typed-uris.rs index 7f366e7e..47d313bc 100644 --- a/core/codegen/tests/typed-uris.rs +++ b/core/codegen/tests/typed-uris.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] #![allow(dead_code, unused_variables)] #[macro_use] extern crate rocket; diff --git a/core/codegen/tests/ui-fail/catchers.rs b/core/codegen/tests/ui-fail/catchers.rs index 627bf0c2..0168f3cd 100644 --- a/core/codegen/tests/ui-fail/catchers.rs +++ b/core/codegen/tests/ui-fail/catchers.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] #[macro_use] extern crate rocket; diff --git a/core/codegen/tests/ui-fail/route-attribute-general-syntax.rs b/core/codegen/tests/ui-fail/route-attribute-general-syntax.rs index 8457f96b..6f3dfda1 100644 --- a/core/codegen/tests/ui-fail/route-attribute-general-syntax.rs +++ b/core/codegen/tests/ui-fail/route-attribute-general-syntax.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] #[macro_use] extern crate rocket; diff --git a/core/codegen/tests/ui-fail/route-path-bad-syntax.rs b/core/codegen/tests/ui-fail/route-path-bad-syntax.rs index ab6a8a4a..1f79e386 100644 --- a/core/codegen/tests/ui-fail/route-path-bad-syntax.rs +++ b/core/codegen/tests/ui-fail/route-path-bad-syntax.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] #[macro_use] extern crate rocket; diff --git a/core/codegen/tests/ui-fail/route-type-errors.rs b/core/codegen/tests/ui-fail/route-type-errors.rs index f97645ae..6cedb32f 100644 --- a/core/codegen/tests/ui-fail/route-type-errors.rs +++ b/core/codegen/tests/ui-fail/route-type-errors.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] #[macro_use] extern crate rocket; diff --git a/core/codegen/tests/ui-fail/route-warnings.rs b/core/codegen/tests/ui-fail/route-warnings.rs index 9111a216..57e3c93d 100644 --- a/core/codegen/tests/ui-fail/route-warnings.rs +++ b/core/codegen/tests/ui-fail/route-warnings.rs @@ -1,6 +1,6 @@ // must-compile-successfully -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] #[macro_use] extern crate rocket; diff --git a/core/codegen/tests/ui-fail/routes.rs b/core/codegen/tests/ui-fail/routes.rs index 954293a5..75952d25 100644 --- a/core/codegen/tests/ui-fail/routes.rs +++ b/core/codegen/tests/ui-fail/routes.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] #[macro_use] extern crate rocket; diff --git a/core/codegen/tests/ui-fail/typed-uri-bad-type.rs b/core/codegen/tests/ui-fail/typed-uri-bad-type.rs index 05b24fb3..82f93101 100644 --- a/core/codegen/tests/ui-fail/typed-uri-bad-type.rs +++ b/core/codegen/tests/ui-fail/typed-uri-bad-type.rs @@ -1,7 +1,7 @@ // normalize-stderr-test: "<(.*) as (.*)>" -> "$1 as $$TRAIT" // normalize-stderr-test: "and \d+ others" -> "and $$N others" -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] #[macro_use] extern crate rocket; diff --git a/core/codegen/tests/ui-fail/typed-uris-bad-params.rs b/core/codegen/tests/ui-fail/typed-uris-bad-params.rs index 2baf5be9..2bde677c 100644 --- a/core/codegen/tests/ui-fail/typed-uris-bad-params.rs +++ b/core/codegen/tests/ui-fail/typed-uris-bad-params.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] #[macro_use] extern crate rocket; diff --git a/core/codegen/tests/ui-fail/typed-uris-invalid-syntax.rs b/core/codegen/tests/ui-fail/typed-uris-invalid-syntax.rs index 0c22cc17..34c71811 100644 --- a/core/codegen/tests/ui-fail/typed-uris-invalid-syntax.rs +++ b/core/codegen/tests/ui-fail/typed-uris-invalid-syntax.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] #[macro_use] extern crate rocket; diff --git a/core/codegen/tests/uri_display.rs b/core/codegen/tests/uri_display.rs index b51d716a..bcd112d4 100644 --- a/core/codegen/tests/uri_display.rs +++ b/core/codegen/tests/uri_display.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] #[macro_use] extern crate rocket; diff --git a/core/http/src/cookies.rs b/core/http/src/cookies.rs index 5a30b94d..c1158773 100644 --- a/core/http/src/cookies.rs +++ b/core/http/src/cookies.rs @@ -53,7 +53,7 @@ mod key { /// a handler to retrieve the value of a "message" cookie. /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// use rocket::http::Cookies; /// @@ -73,7 +73,7 @@ mod key { /// [private cookie]: Cookies::add_private() /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # /// use rocket::http::Status; diff --git a/core/http/src/lib.rs b/core/http/src/lib.rs index c27ed519..37f5d7e6 100644 --- a/core/http/src/lib.rs +++ b/core/http/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] #![recursion_limit="512"] #![warn(rust_2018_idioms)] diff --git a/core/http/src/uri/from_uri_param.rs b/core/http/src/uri/from_uri_param.rs index 4aa374f8..992f899b 100644 --- a/core/http/src/uri/from_uri_param.rs +++ b/core/http/src/uri/from_uri_param.rs @@ -155,7 +155,7 @@ use crate::uri::{self, UriPart, UriDisplay}; /// With these implementations, the following typechecks: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # use std::fmt; /// use rocket::http::RawStr; diff --git a/core/http/src/uri/uri_display.rs b/core/http/src/uri/uri_display.rs index 153778fb..b41f399e 100644 --- a/core/http/src/uri/uri_display.rs +++ b/core/http/src/uri/uri_display.rs @@ -61,7 +61,7 @@ use crate::uri::{Uri, UriPart, Path, Query, Formatter}; /// the following route: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// #[get("/item/?")] /// fn get_item(id: i32, track: Option) { /* .. */ } @@ -70,7 +70,7 @@ use crate::uri::{Uri, UriPart, Path, Query, Formatter}; /// A URI for this route can be generated as follows: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # type T = (); /// # #[get("/item/?")] @@ -234,7 +234,7 @@ use crate::uri::{Uri, UriPart, Path, Query, Formatter}; /// `UriDisplay` implementation is required. /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// use rocket::http::RawStr; /// use rocket::request::FromParam; @@ -432,7 +432,7 @@ impl, E> UriDisplay for Result { /// trait for the corresponding `UriPart`. /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// #[get("/item/?")] /// fn get_item(id: i32, track: Option) { /* .. */ } diff --git a/core/lib/benches/format-routing.rs b/core/lib/benches/format-routing.rs index f71eca05..d20eb2ab 100644 --- a/core/lib/benches/format-routing.rs +++ b/core/lib/benches/format-routing.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] #[macro_use] extern crate rocket; diff --git a/core/lib/benches/ranked-routing.rs b/core/lib/benches/ranked-routing.rs index d782ca79..df5716d2 100644 --- a/core/lib/benches/ranked-routing.rs +++ b/core/lib/benches/ranked-routing.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] #[macro_use] extern crate rocket; diff --git a/core/lib/benches/simple-routing.rs b/core/lib/benches/simple-routing.rs index 27fef79d..8a1da0a6 100644 --- a/core/lib/benches/simple-routing.rs +++ b/core/lib/benches/simple-routing.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene)] +#![feature(proc_macro_hygiene, async_await)] // #![feature(alloc_system)] // extern crate alloc_system; diff --git a/core/lib/src/catcher.rs b/core/lib/src/catcher.rs index 8fb1fa2b..bfc81101 100644 --- a/core/lib/src/catcher.rs +++ b/core/lib/src/catcher.rs @@ -36,7 +36,7 @@ use yansi::Color::*; /// declared using the `catch` decorator, as follows: /// /// ```rust -/// #![feature(proc_macro_hygiene)] +/// #![feature(proc_macro_hygiene, async_await)] /// /// #[macro_use] extern crate rocket; /// @@ -78,16 +78,17 @@ impl Catcher { /// ```rust /// # #![allow(unused_variables)] /// use rocket::{Catcher, Request}; + /// use rocket::handler::ErrorHandlerFuture; /// use rocket::response::{Result, Responder}; /// use rocket::response::status::Custom; /// use rocket::http::Status; /// - /// fn handle_404<'r>(req: &'r Request) -> Result<'r> { - /// let res = Custom(Status::NotFound, format!("404: {}", req.uri())); - /// res.respond_to(req) + /// fn handle_404<'r>(req: &'r Request) -> ErrorHandlerFuture<'r> { + /// let res = Custom(Status::NotFound, format!("404: {}", req.uri())); + /// res.respond_to(req) /// } /// - /// fn handle_500<'r>(req: &'r Request) -> Result<'r> { + /// fn handle_500<'r>(req: &'r Request) -> ErrorHandlerFuture<'r> { /// "Whoops, we messed up!".respond_to(req) /// } /// diff --git a/core/lib/src/data/data.rs b/core/lib/src/data/data.rs index caa32ddc..3b6fb12d 100644 --- a/core/lib/src/data/data.rs +++ b/core/lib/src/data/data.rs @@ -23,7 +23,7 @@ const PEEK_BYTES: usize = 512; /// specifying the `data = ""` route parameter as follows: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # type DataGuard = rocket::data::Data; /// #[post("/submit", data = "")] diff --git a/core/lib/src/fairing/ad_hoc.rs b/core/lib/src/fairing/ad_hoc.rs index dc160491..a2b9f1e2 100644 --- a/core/lib/src/fairing/ad_hoc.rs +++ b/core/lib/src/fairing/ad_hoc.rs @@ -117,12 +117,15 @@ impl AdHoc { /// # Example /// /// ```rust + /// # #![feature(async_await)] /// use rocket::fairing::AdHoc; /// /// // The no-op response fairing. /// let fairing = AdHoc::on_response("Dummy", |req, resp| { - /// // do something with the request and pending response... - /// # let (_, _) = (req, resp); + /// Box::pin(async move { + /// // do something with the request and pending response... + /// # let (_, _) = (req, resp); + /// }) /// }); /// ``` pub fn on_response(name: &'static str, f: F) -> AdHoc diff --git a/core/lib/src/fairing/mod.rs b/core/lib/src/fairing/mod.rs index d895e951..7ee7e14f 100644 --- a/core/lib/src/fairing/mod.rs +++ b/core/lib/src/fairing/mod.rs @@ -20,9 +20,10 @@ //! write: //! //! ```rust +//! # #![feature(async_await)] //! # use rocket::fairing::AdHoc; //! # let req_fairing = AdHoc::on_request("Request", |_, _| ()); -//! # let res_fairing = AdHoc::on_response("Response", |_, _| ()); +//! # let res_fairing = AdHoc::on_response("Response", |_, _| Box::pin(async move {})); //! let rocket = rocket::ignite() //! .attach(req_fairing) //! .attach(res_fairing); @@ -206,7 +207,10 @@ pub use self::info_kind::{Info, Kind}; /// path. /// /// ```rust +/// # #![feature(async_await)] +/// use std::future::Future; /// use std::io::Cursor; +/// use std::pin::Pin; /// use std::sync::atomic::{AtomicUsize, Ordering}; /// /// use rocket::{Request, Data, Response}; @@ -235,21 +239,23 @@ pub use self::info_kind::{Info, Kind}; /// } /// } /// -/// fn on_response(&self, request: &Request, response: &mut Response) { -/// // Don't change a successful user's response, ever. -/// if response.status() != Status::NotFound { -/// return -/// } +/// fn on_response<'a, 'r>(&'a self, request: &'a Request<'r>, response: &'a mut Response<'r>) -> Pin + Send + 'a>> { +/// Box::pin(async move { +/// // Don't change a successful user's response, ever. +/// if response.status() != Status::NotFound { +/// return +/// } /// -/// if request.method() == Method::Get && request.uri().path() == "/counts" { -/// let get_count = self.get.load(Ordering::Relaxed); -/// let post_count = self.post.load(Ordering::Relaxed); +/// if request.method() == Method::Get && request.uri().path() == "/counts" { +/// let get_count = self.get.load(Ordering::Relaxed); +/// let post_count = self.post.load(Ordering::Relaxed); /// -/// let body = format!("Get: {}\nPost: {}", get_count, post_count); -/// response.set_status(Status::Ok); -/// response.set_header(ContentType::Plain); -/// response.set_sized_body(Cursor::new(body)); -/// } +/// let body = format!("Get: {}\nPost: {}", get_count, post_count); +/// response.set_status(Status::Ok); +/// response.set_header(ContentType::Plain); +/// response.set_sized_body(Cursor::new(body)); +/// } +/// }) /// } /// } /// ``` @@ -265,6 +271,9 @@ pub use self::info_kind::{Info, Kind}; /// request guard. /// /// ```rust +/// # #![feature(async_await)] +/// # use std::future::Future; +/// # use std::pin::Pin; /// # use std::time::{Duration, SystemTime}; /// # use rocket::Outcome; /// # use rocket::{Request, Data, Response}; @@ -297,12 +306,14 @@ pub use self::info_kind::{Info, Kind}; /// /// /// Adds a header to the response indicating how long the server took to /// /// process the request. -/// fn on_response(&self, request: &Request, response: &mut Response) { -/// let start_time = request.local_cache(|| TimerStart(None)); -/// if let Some(Ok(duration)) = start_time.0.map(|st| st.elapsed()) { -/// let ms = duration.as_secs() * 1000 + duration.subsec_millis() as u64; -/// response.set_raw_header("X-Response-Time", format!("{} ms", ms)); -/// } +/// fn on_response<'a, 'r>(&'a self, request: &'a Request<'r>, response: &'a mut Response<'r>) -> Pin + Send + 'a>> { +/// Box::pin(async move { +/// let start_time = request.local_cache(|| TimerStart(None)); +/// if let Some(Ok(duration)) = start_time.0.map(|st| st.elapsed()) { +/// let ms = duration.as_secs() * 1000 + duration.subsec_millis() as u64; +/// response.set_raw_header("X-Response-Time", format!("{} ms", ms)); +/// } +/// }) /// } /// } /// diff --git a/core/lib/src/handler.rs b/core/lib/src/handler.rs index ab9fb048..08bdee31 100644 --- a/core/lib/src/handler.rs +++ b/core/lib/src/handler.rs @@ -42,15 +42,16 @@ pub type HandlerFuture<'r> = std::pin::Pin> /// Such a handler might be written and used as follows: /// /// ```rust +/// # #![feature(async_await)] /// # #[derive(Copy, Clone)] enum Kind { Simple, Intermediate, Complex, } /// use rocket::{Request, Data, Route, http::Method}; -/// use rocket::handler::{self, Handler, Outcome}; +/// use rocket::handler::{self, Handler, Outcome, HandlerFuture}; /// /// #[derive(Clone)] /// struct CustomHandler(Kind); /// /// impl Handler for CustomHandler { -/// fn handle<'r>(&self, req: &'r Request, data: Data) -> Outcome<'r> { +/// fn handle<'r>(&self, req: &'r Request, data: Data) -> HandlerFuture<'r> { /// match self.0 { /// Kind::Simple => Outcome::from(req, "simple"), /// Kind::Intermediate => Outcome::from(req, "intermediate"), @@ -91,7 +92,7 @@ pub type HandlerFuture<'r> = std::pin::Pin> /// managed state and a static route, as follows: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # /// # #[derive(Copy, Clone)] @@ -198,10 +199,11 @@ impl<'r> Outcome<'r> { /// # Example /// /// ```rust + /// # #![feature(async_await)] /// use rocket::{Request, Data}; - /// use rocket::handler::Outcome; + /// use rocket::handler::{Outcome, HandlerFuture}; /// - /// fn str_responder(req: &Request, _: Data) -> Outcome<'static> { + /// fn str_responder<'r>(req: &'r Request, _: Data) -> HandlerFuture<'r> { /// Outcome::from(req, "Hello, world!") /// } /// ``` @@ -253,10 +255,11 @@ impl<'r> Outcome<'r> { /// # Example /// /// ```rust + /// # #![feature(async_await)] /// use rocket::{Request, Data}; - /// use rocket::handler::Outcome; + /// use rocket::handler::{Outcome, HandlerFuture}; /// - /// fn str_responder(req: &Request, data: Data) -> Outcome<'static> { + /// fn str_responder<'r>(req: &'r Request, data: Data) -> HandlerFuture<'r> { /// Outcome::from_or_forward(req, data, "Hello, world!") /// } /// ``` @@ -281,12 +284,15 @@ impl<'r> Outcome<'r> { /// # Example /// /// ```rust + /// # #![feature(async_await)] /// use rocket::{Request, Data}; - /// use rocket::handler::Outcome; + /// use rocket::handler::{Outcome, HandlerFuture}; /// use rocket::http::Status; /// - /// fn bad_req_route(_: &Request, _: Data) -> Outcome<'static> { - /// Outcome::failure(Status::BadRequest) + /// fn bad_req_route<'r>(_: &'r Request, _: Data) -> HandlerFuture<'r> { + /// Box::pin(async move { + /// Outcome::failure(Status::BadRequest) + /// }) /// } /// ``` #[inline(always)] @@ -303,11 +309,14 @@ impl<'r> Outcome<'r> { /// # Example /// /// ```rust + /// # #![feature(async_await)] /// use rocket::{Request, Data}; - /// use rocket::handler::Outcome; + /// use rocket::handler::{Outcome, HandlerFuture}; /// - /// fn always_forward(_: &Request, data: Data) -> Outcome<'static> { - /// Outcome::forward(data) + /// fn always_forward<'r>(_: &'r Request, data: Data) -> HandlerFuture<'r> { + /// Box::pin(async move { + /// Outcome::forward(data) + /// }) /// } /// ``` #[inline(always)] diff --git a/core/lib/src/lib.rs b/core/lib/src/lib.rs index 316c929a..59c08f2f 100644 --- a/core/lib/src/lib.rs +++ b/core/lib/src/lib.rs @@ -48,7 +48,7 @@ //! Then, add the following to the top of your `main.rs` file: //! //! ```rust -//! #![feature(proc_macro_hygiene)] +//! #![feature(proc_macro_hygiene, async_await)] //! //! #[macro_use] extern crate rocket; //! # #[get("/")] fn hello() { } @@ -59,7 +59,7 @@ //! write Rocket applications. Here's a simple example to get you started: //! //! ```rust -//! #![feature(proc_macro_hygiene)] +//! #![feature(proc_macro_hygiene, async_await)] //! //! #[macro_use] extern crate rocket; //! diff --git a/core/lib/src/local/mod.rs b/core/lib/src/local/mod.rs index 6265718a..0c66f90b 100644 --- a/core/lib/src/local/mod.rs +++ b/core/lib/src/local/mod.rs @@ -67,7 +67,7 @@ //! consider the following complete "Hello, world!" application, with testing. //! //! ```rust -//! #![feature(proc_macro_hygiene)] +//! #![feature(proc_macro_hygiene, async_await)] //! //! #[macro_use] extern crate rocket; //! diff --git a/core/lib/src/request/form/error.rs b/core/lib/src/request/form/error.rs index 086be805..fdd1b3fc 100644 --- a/core/lib/src/request/form/error.rs +++ b/core/lib/src/request/form/error.rs @@ -50,7 +50,7 @@ pub enum FormDataError<'f, E> { /// # Example /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// use rocket::request::{Form, FormError, FormDataError}; /// diff --git a/core/lib/src/request/form/form.rs b/core/lib/src/request/form/form.rs index 5d13353f..a3053a8c 100644 --- a/core/lib/src/request/form/form.rs +++ b/core/lib/src/request/form/form.rs @@ -33,7 +33,7 @@ use crate::ext::AsyncReadExt as _; /// implements the `FromForm` trait: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// use rocket::request::Form; /// use rocket::http::RawStr; @@ -69,7 +69,7 @@ use crate::ext::AsyncReadExt as _; /// A handler that handles a form of this type can similarly by written: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #![allow(deprecated, unused_attributes)] /// # #[macro_use] extern crate rocket; /// # use rocket::request::Form; @@ -122,7 +122,7 @@ impl Form { /// # Example /// /// ```rust - /// # #![feature(proc_macro_hygiene)] + /// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// use rocket::request::Form; /// diff --git a/core/lib/src/request/form/from_form.rs b/core/lib/src/request/form/from_form.rs index 08c55985..406f7d46 100644 --- a/core/lib/src/request/form/from_form.rs +++ b/core/lib/src/request/form/from_form.rs @@ -13,7 +13,7 @@ use crate::request::FormItems; /// validation. /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #![allow(deprecated, dead_code, unused_attributes)] /// # #[macro_use] extern crate rocket; /// #[derive(FromForm)] @@ -30,7 +30,7 @@ use crate::request::FormItems; /// data via the `data` parameter and `Form` type. /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #![allow(deprecated, dead_code, unused_attributes)] /// # #[macro_use] extern crate rocket; /// # use rocket::request::Form; diff --git a/core/lib/src/request/form/from_form_value.rs b/core/lib/src/request/form/from_form_value.rs index 477639d2..2e083d9b 100644 --- a/core/lib/src/request/form/from_form_value.rs +++ b/core/lib/src/request/form/from_form_value.rs @@ -43,7 +43,7 @@ use crate::http::RawStr; /// according to its target type: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # type Size = String; /// #[get("/item?&")] diff --git a/core/lib/src/request/form/lenient.rs b/core/lib/src/request/form/lenient.rs index d25b3f1c..a70dcce2 100644 --- a/core/lib/src/request/form/lenient.rs +++ b/core/lib/src/request/form/lenient.rs @@ -31,7 +31,7 @@ use crate::http::uri::{Query, FromUriParam}; /// handler: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// use rocket::request::LenientForm; /// @@ -67,7 +67,7 @@ impl LenientForm { /// # Example /// /// ```rust - /// # #![feature(proc_macro_hygiene)] + /// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// use rocket::request::LenientForm; /// diff --git a/core/lib/src/request/from_request.rs b/core/lib/src/request/from_request.rs index 8f603487..cd66d825 100644 --- a/core/lib/src/request/from_request.rs +++ b/core/lib/src/request/from_request.rs @@ -55,7 +55,7 @@ impl IntoOutcome for Result { /// guard. /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # use rocket::http::Method; /// # type A = Method; type B = Method; type C = Method; type T = (); @@ -165,7 +165,7 @@ impl IntoOutcome for Result { /// `sensitive` handler. /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # /// use rocket::Outcome; @@ -220,7 +220,7 @@ impl IntoOutcome for Result { /// routes (`admin_dashboard` and `user_dashboard`): /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # #[cfg(feature = "private-cookies")] mod inner { /// # use rocket::outcome::{IntoOutcome, Outcome}; @@ -283,7 +283,7 @@ impl IntoOutcome for Result { /// used, as illustrated below: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # #[cfg(feature = "private-cookies")] mod inner { /// # use rocket::outcome::{IntoOutcome, Outcome}; diff --git a/core/lib/src/request/param.rs b/core/lib/src/request/param.rs index bcbdd9a5..931f5c2f 100644 --- a/core/lib/src/request/param.rs +++ b/core/lib/src/request/param.rs @@ -19,7 +19,7 @@ use crate::http::{RawStr, uri::{Segments, SegmentError}}; /// handler for the dynamic `"/"` path: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// #[get("/")] /// fn hello(id: usize) -> String { @@ -54,7 +54,7 @@ use crate::http::{RawStr, uri::{Segments, SegmentError}}; /// parameter as follows: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # use rocket::http::RawStr; /// #[get("/")] @@ -172,7 +172,7 @@ use crate::http::{RawStr, uri::{Segments, SegmentError}}; /// dynamic path segment: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # use rocket::request::FromParam; /// # use rocket::http::RawStr; diff --git a/core/lib/src/request/query.rs b/core/lib/src/request/query.rs index d6a4d55b..af25bf69 100644 --- a/core/lib/src/request/query.rs +++ b/core/lib/src/request/query.rs @@ -8,7 +8,7 @@ use crate::request::{FormItems, FormItem, Form, LenientForm, FromForm}; /// generation for every trailing query parameter, `` below: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # /// # use rocket::request::Form; @@ -82,7 +82,7 @@ impl<'q> Iterator for Query<'q> { /// route: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// use rocket::request::Form; /// diff --git a/core/lib/src/request/state.rs b/core/lib/src/request/state.rs index 54370a3d..f45cf559 100644 --- a/core/lib/src/request/state.rs +++ b/core/lib/src/request/state.rs @@ -22,7 +22,7 @@ use crate::http::Status; /// following example does just this: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// use rocket::State; /// @@ -87,7 +87,7 @@ use crate::http::Status; /// [`State::from()`] static method: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// use rocket::State; /// diff --git a/core/lib/src/response/flash.rs b/core/lib/src/response/flash.rs index 2251156a..35a5689c 100644 --- a/core/lib/src/response/flash.rs +++ b/core/lib/src/response/flash.rs @@ -45,7 +45,7 @@ const FLASH_COOKIE_NAME: &str = "_flash"; /// message on both the request and response sides. /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// use rocket::response::{Flash, Redirect}; /// use rocket::request::FlashMessage; diff --git a/core/lib/src/response/redirect.rs b/core/lib/src/response/redirect.rs index d891fdac..8d5017a1 100644 --- a/core/lib/src/response/redirect.rs +++ b/core/lib/src/response/redirect.rs @@ -26,7 +26,7 @@ use crate::http::Status; /// a route, _always_ use [`uri!`] to construct a valid [`Origin`]: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// use rocket::response::Redirect; /// diff --git a/core/lib/src/response/responder.rs b/core/lib/src/response/responder.rs index 18605960..a5e6ab0a 100644 --- a/core/lib/src/response/responder.rs +++ b/core/lib/src/response/responder.rs @@ -13,7 +13,7 @@ use crate::request::Request; /// as illustrated below with `T`: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # type T = (); /// # @@ -154,7 +154,7 @@ use crate::request::Request; /// following `Responder` implementation accomplishes this: /// /// ```rust -/// # #![feature(proc_macro_hygiene)] +/// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # /// # #[derive(Debug)] @@ -166,14 +166,16 @@ use crate::request::Request; /// use rocket::response::{self, Response, Responder}; /// use rocket::http::ContentType; /// -/// impl Responder<'_> for Person { -/// fn respond_to(self, _: &Request) -> response::Result<'static> { -/// Response::build() -/// .sized_body(Cursor::new(format!("{}:{}", self.name, self.age))) -/// .raw_header("X-Person-Name", self.name) -/// .raw_header("X-Person-Age", self.age.to_string()) -/// .header(ContentType::new("application", "x-person")) -/// .ok() +/// impl Responder<'r> for Person { +/// fn respond_to(self, _: &'r Request) -> response::ResultFuture<'r> { +/// Box::pin(async move { +/// Response::build() +/// .sized_body(Cursor::new(format!("{}:{}", self.name, self.age))) +/// .raw_header("X-Person-Name", self.name) +/// .raw_header("X-Person-Age", self.age.to_string()) +/// .header(ContentType::new("application", "x-person")) +/// .ok() +/// }) /// } /// } /// # diff --git a/core/lib/src/rocket.rs b/core/lib/src/rocket.rs index a1a3add3..9538a9d9 100644 --- a/core/lib/src/rocket.rs +++ b/core/lib/src/rocket.rs @@ -513,7 +513,7 @@ impl Rocket { /// dispatched to the `hi` route. /// /// ```rust - /// # #![feature(proc_macro_hygiene)] + /// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// # /// #[get("/world")] @@ -535,10 +535,10 @@ impl Rocket { /// /// ```rust /// use rocket::{Request, Route, Data}; - /// use rocket::handler::Outcome; + /// use rocket::handler::{HandlerFuture, Outcome}; /// use rocket::http::Method::*; /// - /// fn hi<'r>(req: &'r Request, _: Data) -> Outcome<'r> { + /// fn hi<'r>(req: &'r Request, _: Data) -> HandlerFuture<'r> { /// Outcome::from(req, "Hello!") /// } /// @@ -585,7 +585,7 @@ impl Rocket { /// # Examples /// /// ```rust - /// # #![feature(proc_macro_hygiene)] + /// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// use rocket::Request; /// @@ -641,7 +641,7 @@ impl Rocket { /// # Example /// /// ```rust - /// # #![feature(proc_macro_hygiene)] + /// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// use rocket::State; /// @@ -678,7 +678,7 @@ impl Rocket { /// # Example /// /// ```rust - /// # #![feature(proc_macro_hygiene)] + /// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// use rocket::Rocket; /// use rocket::fairing::AdHoc; @@ -819,7 +819,7 @@ impl Rocket { /// # Example /// /// ```rust - /// # #![feature(proc_macro_hygiene)] + /// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// use rocket::Rocket; /// use rocket::fairing::AdHoc; @@ -875,7 +875,7 @@ impl Rocket { /// # Example /// /// ```rust - /// # #![feature(proc_macro_hygiene)] + /// # #![feature(proc_macro_hygiene, async_await)] /// # #[macro_use] extern crate rocket; /// use rocket::Rocket; /// use rocket::fairing::AdHoc; diff --git a/core/lib/src/router/route.rs b/core/lib/src/router/route.rs index 3ec2363c..0d062da3 100644 --- a/core/lib/src/router/route.rs +++ b/core/lib/src/router/route.rs @@ -108,8 +108,8 @@ impl Route { /// use rocket::Route; /// use rocket::http::Method; /// # use rocket::{Request, Data}; - /// # use rocket::handler::Outcome; - /// # fn handler<'r>(request: &'r Request, _data: Data) -> Outcome<'r> { + /// # use rocket::handler::{Outcome, HandlerFuture}; + /// # fn handler<'r>(request: &'r Request, _data: Data) -> HandlerFuture<'r> { /// # Outcome::from(request, "Hello, world!") /// # } /// @@ -158,8 +158,8 @@ impl Route { /// use rocket::Route; /// use rocket::http::Method; /// # use rocket::{Request, Data}; - /// # use rocket::handler::Outcome; - /// # fn handler<'r>(request: &'r Request, _data: Data) -> Outcome<'r> { + /// # use rocket::handler::{Outcome, HandlerFuture}; + /// # fn handler<'r>(request: &'r Request, _data: Data) -> HandlerFuture<'r> { /// # Outcome::from(request, "Hello, world!") /// # } /// @@ -208,9 +208,9 @@ impl Route { /// use rocket::Route; /// use rocket::http::Method; /// # use rocket::{Request, Data}; - /// # use rocket::handler::Outcome; + /// # use rocket::handler::{Outcome, HandlerFuture}; /// # - /// # fn handler<'r>(request: &'r Request, _data: Data) -> Outcome<'r> { + /// # fn handler<'r>(request: &'r Request, _data: Data) -> HandlerFuture<'r> { /// # Outcome::from(request, "Hello, world!") /// # } /// @@ -242,9 +242,9 @@ impl Route { /// use rocket::Route; /// use rocket::http::{Method, uri::Origin}; /// # use rocket::{Request, Data}; - /// # use rocket::handler::Outcome; + /// # use rocket::handler::{Outcome, HandlerFuture}; /// # - /// # fn handler<'r>(request: &'r Request, _data: Data) -> Outcome<'r> { + /// # fn handler<'r>(request: &'r Request, _data: Data) -> HandlerFuture<'r> { /// # Outcome::from(request, "Hello, world!") /// # } ///