From a6420145652db48de65d0e2b707a122d6de9d64d Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sat, 23 Apr 2022 20:58:32 +0100 Subject: [PATCH] tweak FromRequest::Future docs --- actix-web/src/extract.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/actix-web/src/extract.rs b/actix-web/src/extract.rs index 88a401a3d..9d9ca889e 100644 --- a/actix-web/src/extract.rs +++ b/actix-web/src/extract.rs @@ -66,21 +66,29 @@ pub trait FromRequest: Sized { /// The associated error which can be returned. type Error: Into; - /// Future that resolves to a Self. + /// Future that resolves to a `Self`. /// - /// To use an async function or block here, you can a boxed future such as `futures::future::LocalBoxFuture`. - /// This is an alias for a pinned Box, so you can create it with the following syntax: - /// ``` - /// Box::pin(async { - /// ... - /// }) + /// To use an async function or block, the futures must be boxed. The following snippet will be + /// common when creating async/await extractors (that do not consume the body). + /// + /// ```ignore + /// type Future = Pin>>>; + /// // or + /// type Future = futures_util::future::LocalBoxFuture<'static, Result>; + /// + /// fn from_request(req: HttpRequest, ...) -> Self::Future { + /// let req = req.clone(); + /// Box::pin(async move { + /// ... + /// }) + /// } /// ``` type Future: Future>; - /// Create a Self from request parts asynchronously. + /// Create a `Self` from request parts asynchronously. fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future; - /// Create a Self from request head asynchronously. + /// Create a `Self` from request head asynchronously. /// /// This method is short for `T::from_request(req, &mut Payload::None)`. fn extract(req: &HttpRequest) -> Self::Future {