Inner field of web::Query is public again (#2016)

This commit is contained in:
Adam Chalmers 2021-02-19 18:26:14 -06:00
parent 83365058ce
commit 7075f47c25
2 changed files with 17 additions and 2 deletions

View File

@ -5,6 +5,7 @@
* Feature `cookies` is now optional and enabled by default. [#1981] * Feature `cookies` is now optional and enabled by default. [#1981]
* `JsonBody::new` returns a default limit of 32kB to be consistent with `JsonConfig` and the * `JsonBody::new` returns a default limit of 32kB to be consistent with `JsonConfig` and the
default behaviour of the `web::Json<T>` extractor. [#2010] default behaviour of the `web::Json<T>` extractor. [#2010]
* `web::Query` has a public inner field again [#2016]
[#1981]: https://github.com/actix/actix-web/pull/1981 [#1981]: https://github.com/actix/actix-web/pull/1981
[#2010]: https://github.com/actix/actix-web/pull/2010 [#2010]: https://github.com/actix/actix-web/pull/2010

View File

@ -29,7 +29,7 @@ use crate::{dev::Payload, error::QueryPayloadError, Error, FromRequest, HttpRequ
/// Code /// Code
/// } /// }
/// ///
/// #[derive(Deserialize)] /// #[derive(Debug, Deserialize)]
/// pub struct AuthRequest { /// pub struct AuthRequest {
/// id: u64, /// id: u64,
/// response_type: ResponseType, /// response_type: ResponseType,
@ -42,9 +42,23 @@ use crate::{dev::Payload, error::QueryPayloadError, Error, FromRequest, HttpRequ
/// async fn index(info: web::Query<AuthRequest>) -> String { /// async fn index(info: web::Query<AuthRequest>) -> String {
/// format!("Authorization request for id={} and type={:?}!", info.id, info.response_type) /// format!("Authorization request for id={} and type={:?}!", info.id, info.response_type)
/// } /// }
///
/// // To access the entire underlying query struct, use `.into_inner()`.
/// #[get("/debug1")]
/// async fn debug1(info: web::Query<AuthRequest>) -> String {
/// dbg!("Authorization object={:?}", info.into_inner());
/// "OK".to_string()
/// }
///
/// // Or use `.0`, which is equivalent to `.into_inner()`.
/// #[get("/debug2")]
/// async fn debug2(info: web::Query<AuthRequest>) -> String {
/// dbg!("Authorization object={:?}", info.0);
/// "OK".to_string()
/// }
/// ``` /// ```
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)] #[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Query<T>(T); pub struct Query<T>(pub T);
impl<T> Query<T> { impl<T> Query<T> {
/// Unwrap into inner `T` value. /// Unwrap into inner `T` value.