From a6f4d640a5bcd8c2549f07ecb9e2beac688074b2 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Sun, 18 Apr 2021 11:12:50 +0200 Subject: support borrowing for URL query deserialization --- src/request.rs | 6 +++--- 1 file 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(&self) -> Result; + fn query<'a, X: Deserialize<'a>>(&'a self) -> Result; /// 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(&self) -> Result { + fn query<'a, T: Deserialize<'a>>(&'a self) -> Result { serde_urlencoded::from_str::(self.uri.query().unwrap_or("")).map_err(QueryError) } -- cgit v1.2.3