From 7075f47c25405abe7c1a29c0dbbcfa4cf1f12e91 Mon Sep 17 00:00:00 2001 From: Adam Chalmers Date: Fri, 19 Feb 2021 18:26:14 -0600 Subject: [PATCH 1/2] Inner field of web::Query is public again (#2016) --- CHANGES.md | 1 + src/types/query.rs | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 7cb03c30cd9..240f8b47ce2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ * 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 default behaviour of the `web::Json` extractor. [#2010] +* `web::Query` has a public inner field again [#2016] [#1981]: https://github.com/actix/actix-web/pull/1981 [#2010]: https://github.com/actix/actix-web/pull/2010 diff --git a/src/types/query.rs b/src/types/query.rs index 691a4792b79..79af3258181 100644 --- a/src/types/query.rs +++ b/src/types/query.rs @@ -29,7 +29,7 @@ use crate::{dev::Payload, error::QueryPayloadError, Error, FromRequest, HttpRequ /// Code /// } /// -/// #[derive(Deserialize)] +/// #[derive(Debug, Deserialize)] /// pub struct AuthRequest { /// id: u64, /// response_type: ResponseType, @@ -42,9 +42,23 @@ use crate::{dev::Payload, error::QueryPayloadError, Error, FromRequest, HttpRequ /// async fn index(info: web::Query) -> String { /// 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) -> 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) -> String { +/// dbg!("Authorization object={:?}", info.0); +/// "OK".to_string() +/// } /// ``` #[derive(Clone, PartialEq, Eq, PartialOrd, Ord)] -pub struct Query(T); +pub struct Query(pub T); impl Query { /// Unwrap into inner `T` value. From 7ac4615bd0539ed2924d802f0b2f013ead49ec67 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sat, 20 Feb 2021 17:30:34 +0000 Subject: [PATCH 2/2] Update CHANGES.md --- CHANGES.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 240f8b47ce2..7cb03c30cd9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,6 @@ * 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 default behaviour of the `web::Json` extractor. [#2010] -* `web::Query` has a public inner field again [#2016] [#1981]: https://github.com/actix/actix-web/pull/1981 [#2010]: https://github.com/actix/actix-web/pull/2010