File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -620,6 +620,8 @@ impl Request {
620620 /// use http_types::Request;
621621 /// use std::collections::HashMap;
622622 ///
623+ /// // An owned structure:
624+ ///
623625 /// #[derive(Deserialize)]
624626 /// # #[serde(crate = "serde_crate")]
625627 /// struct Index {
@@ -632,9 +634,21 @@ impl Request {
632634 /// assert_eq!(page, 2);
633635 /// assert_eq!(selections["width"], "narrow");
634636 /// assert_eq!(selections["height"], "tall");
637+ ///
638+ /// // Using borrows:
639+ ///
640+ /// #[derive(Deserialize)]
641+ /// # #[serde(crate = "serde_crate")]
642+ /// struct Query<'q> {
643+ /// format: &'q str,
644+ /// }
645+ ///
646+ /// let mut req = Request::get("https://httpbin.org/get?format=bananna");
647+ /// let Query { format } = req.query().unwrap();
648+ /// assert_eq!(format, "bananna");
635649 /// ```
636650 #[ cfg( feature = "serde" ) ]
637- pub fn query < T : serde_crate:: de:: DeserializeOwned > ( & self ) -> crate :: Result < T > {
651+ pub fn query < ' de , T : serde_crate:: de:: Deserialize < ' de > > ( & ' de self ) -> crate :: Result < T > {
638652 // Default to an empty query string if no query parameter has been specified.
639653 // This allows successful deserialisation of structs where all fields are optional
640654 // when none of those fields has actually been passed by the caller.
You can’t perform that action at this time.
0 commit comments