1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-02-17 10:13:30 +01:00

improve extract docs (#2384)

This commit is contained in:
Rob Ede 2021-09-11 16:48:47 +01:00 committed by GitHub
parent 8ae278cb68
commit 450ff5fa1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 14 deletions

View File

@ -2,9 +2,12 @@
## Unreleased - 2021-xx-xx ## Unreleased - 2021-xx-xx
### Changed ### Changed
* Asscociated type `FromRequest::Config` was removed. [#2233] * Associated type `FromRequest::Config` was removed. [#2233]
* Inner field made private on `web::Payload`. [#????]
[#2233]: https://github.com/actix/actix-web/pull/2233 [#2233]: https://github.com/actix/actix-web/pull/2233
[#????]: https://github.com/actix/actix-web/pull/????
## 4.0.0-beta.9 - 2021-09-09 ## 4.0.0-beta.9 - 2021-09-09
### Added ### Added

View File

@ -13,28 +13,37 @@ use futures_core::ready;
use crate::{dev::Payload, Error, HttpRequest}; use crate::{dev::Payload, Error, HttpRequest};
/// A type that implements [`FromRequest`] is called an **extractor** and can extract data /// A type that implements [`FromRequest`] is called an **extractor** and can extract data from
/// from the request. Examples of types that implement this trait are [`Json`], [`Form`], [`Path`]. /// the request. Some types that implement this trait are: [`Json`], [`Header`], and [`Path`].
/// ///
/// # Configuration
/// An extractor can be customized by injecting the corresponding configuration with one of: /// An extractor can be customized by injecting the corresponding configuration with one of:
/// ///
/// - [`App::app_data()`](`crate::App::app_data`) /// - [`App::app_data()`][crate::App::app_data]
/// - [`Scope::app_data()`](`crate::Scope::app_data`) /// - [`Scope::app_data()`][crate::Scope::app_data]
/// - [`Resource::app_data()`](`crate::Resource::app_data`) /// - [`Resource::app_data()`][crate::Resource::app_data]
/// ///
/// Here are some built-in extractors and their corresponding configuration. /// Here are some built-in extractors and their corresponding configuration.
/// Please refer to the respective documentation for details. /// Please refer to the respective documentation for details.
/// ///
/// | Extractor | Configuration | /// | Extractor | Configuration |
/// |-------------|-------------------| /// |-------------|-------------------|
/// | [`Header`] | _None_ |
/// | [`Path`] | [`PathConfig`] |
/// | [`Json`] | [`JsonConfig`] | /// | [`Json`] | [`JsonConfig`] |
/// | [`Form`] | [`FormConfig`] | /// | [`Form`] | [`FormConfig`] |
/// | [`Path`] | [`PathConfig`] |
/// | [`Query`] | [`QueryConfig`] | /// | [`Query`] | [`QueryConfig`] |
/// | [`Payload`] | [`PayloadConfig`] |
/// | [`String`] | [`PayloadConfig`] |
/// | [`Bytes`] | [`PayloadConfig`] | /// | [`Bytes`] | [`PayloadConfig`] |
/// | [`String`] | [`PayloadConfig`] |
/// | [`Payload`] | [`PayloadConfig`] |
/// ///
/// # Implementing An Extractor
/// To reduce duplicate code in handlers where extracting certain parts of a request has a common
/// structure, you can implement `FromRequest` for your own types.
///
/// Note that the request payload can only be consumed by one extractor.
///
/// [`Header`]: crate::web::Header
/// [`Json`]: crate::web::Json /// [`Json`]: crate::web::Json
/// [`JsonConfig`]: crate::web::JsonConfig /// [`JsonConfig`]: crate::web::JsonConfig
/// [`Form`]: crate::web::Form /// [`Form`]: crate::web::Form
@ -47,7 +56,8 @@ use crate::{dev::Payload, Error, HttpRequest};
/// [`PayloadConfig`]: crate::web::PayloadConfig /// [`PayloadConfig`]: crate::web::PayloadConfig
/// [`String`]: FromRequest#impl-FromRequest-for-String /// [`String`]: FromRequest#impl-FromRequest-for-String
/// [`Bytes`]: crate::web::Bytes#impl-FromRequest /// [`Bytes`]: crate::web::Bytes#impl-FromRequest
#[cfg_attr(docsrs, doc(alias = "Extractor"))] /// [`Either`]: crate::web::Either
#[doc(alias = "extract", alias = "extractor")]
pub trait FromRequest: Sized { pub trait FromRequest: Sized {
/// The associated error which can be returned. /// The associated error which can be returned.
type Error: Into<Error>; type Error: Into<Error>;

View File

@ -32,7 +32,7 @@ use crate::{
/// To extract typed data from a request body, the inner type `T` must implement the /// To extract typed data from a request body, the inner type `T` must implement the
/// [`DeserializeOwned`] trait. /// [`DeserializeOwned`] trait.
/// ///
/// Use [`FormConfig`] to configure extraction process. /// Use [`FormConfig`] to configure extraction options.
/// ///
/// ``` /// ```
/// use actix_web::{post, web}; /// use actix_web::{post, web};

View File

@ -34,7 +34,7 @@ use crate::{
/// To extract typed data from a request body, the inner type `T` must implement the /// To extract typed data from a request body, the inner type `T` must implement the
/// [`serde::Deserialize`] trait. /// [`serde::Deserialize`] trait.
/// ///
/// Use [`JsonConfig`] to configure extraction process. /// Use [`JsonConfig`] to configure extraction options.
/// ///
/// ``` /// ```
/// use actix_web::{post, web, App}; /// use actix_web::{post, web, App};

View File

@ -14,7 +14,7 @@ use crate::{
/// Extract typed data from request path segments. /// Extract typed data from request path segments.
/// ///
/// Use [`PathConfig`] to configure extraction process. /// Use [`PathConfig`] to configure extraction option.
/// ///
/// # Examples /// # Examples
/// ``` /// ```

View File

@ -43,10 +43,11 @@ use crate::{
/// Ok(format!("Request Body Bytes:\n{:?}", bytes)) /// Ok(format!("Request Body Bytes:\n{:?}", bytes))
/// } /// }
/// ``` /// ```
pub struct Payload(pub crate::dev::Payload); pub struct Payload(crate::dev::Payload);
impl Payload { impl Payload {
/// Unwrap to inner Payload type. /// Unwrap to inner Payload type.
#[inline]
pub fn into_inner(self) -> crate::dev::Payload { pub fn into_inner(self) -> crate::dev::Payload {
self.0 self.0
} }