tweak FromRequest::Future docs

This commit is contained in:
Rob Ede 2022-04-23 20:58:32 +01:00
parent 18ce0b644e
commit a642014565
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
1 changed files with 17 additions and 9 deletions

View File

@ -66,21 +66,29 @@ pub trait FromRequest: Sized {
/// The associated error which can be returned.
type Error: Into<Error>;
/// 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<Box<dyn Future<Output = Result<Self, Self::Error>>>>;
/// // or
/// type Future = futures_util::future::LocalBoxFuture<'static, Result<Self, Self::Error>>;
///
/// fn from_request(req: HttpRequest, ...) -> Self::Future {
/// let req = req.clone();
/// Box::pin(async move {
/// ...
/// })
/// }
/// ```
type Future: Future<Output = Result<Self, Self::Error>>;
/// 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 {