diff options
author | Martin Fischer <martin@push-f.com> | 2021-04-18 11:12:50 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-04-18 11:12:52 +0200 |
commit | a6f4d640a5bcd8c2549f07ecb9e2beac688074b2 (patch) | |
tree | 0ae8ddf3be12a258772a3d7d2b5c1ce938b5a54c | |
parent | e731a5f94e1062cb62c2f8e9e123aee528b322ac (diff) |
support borrowing for URL query deserialization
-rw-r--r-- | src/request.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/request.rs b/src/request.rs index 4f45e04..19292a1 100644 --- a/src/request.rs +++ b/src/request.rs @@ -1,7 +1,7 @@ //! Provides the [`SputnikParts`] trait. use mime::Mime; -use serde::de::DeserializeOwned; +use serde::Deserialize; use std::str::Split; use std::time::Duration; @@ -11,7 +11,7 @@ use crate::http::{HeaderMap, header, request::Parts}; /// Adds convenience methods to [`http::request::Parts`](Parts). pub trait SputnikParts { /// Parses the query string of the request into a given struct. - fn query<X: DeserializeOwned>(&self) -> Result<X,QueryError>; + fn query<'a, X: Deserialize<'a>>(&'a self) -> Result<X,QueryError>; /// Parses the cookies of the request. fn cookies(&self) -> CookieIter; @@ -52,7 +52,7 @@ impl<'a> Iterator for CookieIter<'a> { } impl SputnikParts for Parts { - fn query<T: DeserializeOwned>(&self) -> Result<T,QueryError> { + fn query<'a, T: Deserialize<'a>>(&'a self) -> Result<T,QueryError> { serde_urlencoded::from_str::<T>(self.uri.query().unwrap_or("")).map_err(QueryError) } |