11use axum:: {
2- extract:: { FromRequestParts , OptionalFromRequestParts } ,
2+ extract:: FromRequestParts ,
33 response:: { IntoResponse , Response } ,
44 Error ,
55} ;
@@ -18,19 +18,6 @@ use std::fmt;
1818/// with the `multiple` attribute. Those values can be collected into a `Vec` or other sequential
1919/// container.
2020///
21- /// # `Option<Query<T>>` behavior
22- ///
23- /// If `Query<T>` itself is used as an extractor and there is no query string in
24- /// the request URL, `T`'s `Deserialize` implementation is called on an empty
25- /// string instead.
26- ///
27- /// You can avoid this by using `Option<Query<T>>`, which gives you `None` in
28- /// the case that there is no query string in the request URL.
29- ///
30- /// Note that an empty query string is not the same as no query string, that is
31- /// `https://example.org/` and `https://example.org/?` are not treated the same
32- /// in this case.
33- ///
3421/// # Example
3522///
3623/// ```rust,no_run
@@ -111,29 +98,6 @@ where
11198 }
11299}
113100
114- impl < T , S > OptionalFromRequestParts < S > for Query < T >
115- where
116- T : DeserializeOwned ,
117- S : Send + Sync ,
118- {
119- type Rejection = QueryRejection ;
120-
121- async fn from_request_parts (
122- parts : & mut Parts ,
123- _state : & S ,
124- ) -> Result < Option < Self > , Self :: Rejection > {
125- if let Some ( query) = parts. uri . query ( ) {
126- let deserializer =
127- serde_html_form:: Deserializer :: new ( form_urlencoded:: parse ( query. as_bytes ( ) ) ) ;
128- let value = serde_path_to_error:: deserialize ( deserializer)
129- . map_err ( |err| QueryRejection :: FailedToDeserializeQueryString ( Error :: new ( err) ) ) ?;
130- Ok ( Some ( Self ( value) ) )
131- } else {
132- Ok ( None )
133- }
134- }
135- }
136-
137101axum_core:: __impl_deref!( Query ) ;
138102
139103/// Rejection used for [`Query`].
@@ -181,8 +145,8 @@ impl std::error::Error for QueryRejection {
181145}
182146
183147/// Extractor that deserializes query strings into `None` if no query parameters are present.
184- /// Otherwise behaviour is identical to [`Query`]
185148///
149+ /// Otherwise behaviour is identical to [`Query`].
186150/// `T` is expected to implement [`serde::Deserialize`].
187151///
188152/// # Example
@@ -220,11 +184,9 @@ impl std::error::Error for QueryRejection {
220184///
221185/// [example]: https://github.com/tokio-rs/axum/blob/main/examples/query-params-with-empty-strings/src/main.rs
222186#[ cfg_attr( docsrs, doc( cfg( feature = "query" ) ) ) ]
223- #[ deprecated = "Use Option<Query<_>> instead" ]
224187#[ derive( Debug , Clone , Copy , Default ) ]
225188pub struct OptionalQuery < T > ( pub Option < T > ) ;
226189
227- #[ allow( deprecated) ]
228190impl < T , S > FromRequestParts < S > for OptionalQuery < T >
229191where
230192 T : DeserializeOwned ,
@@ -246,7 +208,6 @@ where
246208 }
247209}
248210
249- #[ allow( deprecated) ]
250211impl < T > std:: ops:: Deref for OptionalQuery < T > {
251212 type Target = Option < T > ;
252213
@@ -256,7 +217,6 @@ impl<T> std::ops::Deref for OptionalQuery<T> {
256217 }
257218}
258219
259- #[ allow( deprecated) ]
260220impl < T > std:: ops:: DerefMut for OptionalQuery < T > {
261221 #[ inline]
262222 fn deref_mut ( & mut self ) -> & mut Self :: Target {
@@ -304,7 +264,6 @@ impl std::error::Error for OptionalQueryRejection {
304264}
305265
306266#[ cfg( test) ]
307- #[ allow( deprecated) ]
308267mod tests {
309268 use super :: * ;
310269 use crate :: test_helpers:: * ;
0 commit comments