From 226ddb4b27eee87f63828d6f0d29da5447798cdd Mon Sep 17 00:00:00 2001 From: rob Date: Wed, 27 Nov 2024 22:20:17 -0500 Subject: [PATCH 1/4] feat: TryInto trait bound for requests::Builder This makes requests::Builder trait bound easily readable and consistent w/ stdlib recommendations --- src/request.rs | 62 +++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/request.rs b/src/request.rs index d4c5bf54..ee9d94a6 100644 --- a/src/request.rs +++ b/src/request.rs @@ -53,7 +53,7 @@ //! ``` use std::any::Any; -use std::convert::TryFrom; +use std::convert::TryInto; use std::fmt; use crate::header::{HeaderMap, HeaderName, HeaderValue}; @@ -231,8 +231,8 @@ impl Request<()> { /// ``` pub fn get(uri: T) -> Builder where - Uri: TryFrom, - >::Error: Into, + T: TryInto, + >::Error: Into, { Builder::new().method(Method::GET).uri(uri) } @@ -253,8 +253,8 @@ impl Request<()> { /// ``` pub fn put(uri: T) -> Builder where - Uri: TryFrom, - >::Error: Into, + T: TryInto, + >::Error: Into, { Builder::new().method(Method::PUT).uri(uri) } @@ -275,8 +275,8 @@ impl Request<()> { /// ``` pub fn post(uri: T) -> Builder where - Uri: TryFrom, - >::Error: Into, + T: TryInto, + >::Error: Into, { Builder::new().method(Method::POST).uri(uri) } @@ -297,8 +297,8 @@ impl Request<()> { /// ``` pub fn delete(uri: T) -> Builder where - Uri: TryFrom, - >::Error: Into, + T: TryInto, + >::Error: Into, { Builder::new().method(Method::DELETE).uri(uri) } @@ -320,8 +320,8 @@ impl Request<()> { /// ``` pub fn options(uri: T) -> Builder where - Uri: TryFrom, - >::Error: Into, + T: TryInto, + >::Error: Into { Builder::new().method(Method::OPTIONS).uri(uri) } @@ -342,8 +342,8 @@ impl Request<()> { /// ``` pub fn head(uri: T) -> Builder where - Uri: TryFrom, - >::Error: Into, + T: TryInto, + >::Error: Into { Builder::new().method(Method::HEAD).uri(uri) } @@ -364,8 +364,8 @@ impl Request<()> { /// ``` pub fn connect(uri: T) -> Builder where - Uri: TryFrom, - >::Error: Into, + T: TryInto, + >::Error: Into { Builder::new().method(Method::CONNECT).uri(uri) } @@ -386,8 +386,8 @@ impl Request<()> { /// ``` pub fn patch(uri: T) -> Builder where - Uri: TryFrom, - >::Error: Into, + T: TryInto, + >::Error: Into { Builder::new().method(Method::PATCH).uri(uri) } @@ -408,8 +408,8 @@ impl Request<()> { /// ``` pub fn trace(uri: T) -> Builder where - Uri: TryFrom, - >::Error: Into, + T: TryInto, + >::Error: Into { Builder::new().method(Method::TRACE).uri(uri) } @@ -767,11 +767,11 @@ impl Builder { /// ``` pub fn method(self, method: T) -> Builder where - Method: TryFrom, - >::Error: Into, + T: TryInto, + >::Error: Into { self.and_then(move |mut head| { - let method = TryFrom::try_from(method).map_err(Into::into)?; + let method = method.try_into().map_err(Into::into)?; head.method = method; Ok(head) }) @@ -812,11 +812,11 @@ impl Builder { /// ``` pub fn uri(self, uri: T) -> Builder where - Uri: TryFrom, - >::Error: Into, + T: TryInto, + >::Error: Into { self.and_then(move |mut head| { - head.uri = TryFrom::try_from(uri).map_err(Into::into)?; + head.uri = uri.try_into().map_err(Into::into)?; Ok(head) }) } @@ -900,14 +900,14 @@ impl Builder { /// ``` pub fn header(self, key: K, value: V) -> Builder where - HeaderName: TryFrom, - >::Error: Into, - HeaderValue: TryFrom, - >::Error: Into, + K: TryInto, + >::Error: Into, + V: TryInto, + >::Error: Into, { self.and_then(move |mut head| { - let name = >::try_from(key).map_err(Into::into)?; - let value = >::try_from(value).map_err(Into::into)?; + let name = key.try_into().map_err(Into::into)?; + let value = value.try_into().map_err(Into::into)?; head.headers.try_append(name, value)?; Ok(head) }) From adef8031a1f84160dff8715ca7753a94226c6905 Mon Sep 17 00:00:00 2001 From: rob Date: Wed, 27 Nov 2024 23:46:21 -0500 Subject: [PATCH 2/4] feat: TryInto trait bound for response::Builder --- src/response.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/response.rs b/src/response.rs index 312cc5f8..01f7e3d1 100644 --- a/src/response.rs +++ b/src/response.rs @@ -62,13 +62,13 @@ //! ``` use std::any::Any; -use std::convert::TryFrom; +use std::convert::TryInto; use std::fmt; use crate::header::{HeaderMap, HeaderName, HeaderValue}; use crate::status::StatusCode; use crate::version::Version; -use crate::{Extensions, Result}; +use crate::{ Extensions, Result}; /// Represents an HTTP response /// @@ -559,11 +559,11 @@ impl Builder { /// ``` pub fn status(self, status: T) -> Builder where - StatusCode: TryFrom, - >::Error: Into, + T: TryInto, + >::Error: Into, { self.and_then(move |mut head| { - head.status = TryFrom::try_from(status).map_err(Into::into)?; + head.status = status.try_into().map_err(Into::into)?; Ok(head) }) } @@ -610,14 +610,14 @@ impl Builder { /// ``` pub fn header(self, key: K, value: V) -> Builder where - HeaderName: TryFrom, - >::Error: Into, - HeaderValue: TryFrom, - >::Error: Into, + K: TryInto, + >::Error: Into, + V: TryInto, + >::Error: Into, { self.and_then(move |mut head| { - let name = >::try_from(key).map_err(Into::into)?; - let value = >::try_from(value).map_err(Into::into)?; + let name = key.try_into().map_err(Into::into)?; + let value = value.try_into().map_err(Into::into)?; head.headers.try_append(name, value)?; Ok(head) }) From dded3e8953045e108826bea7fa714ee886952830 Mon Sep 17 00:00:00 2001 From: rob Date: Wed, 27 Nov 2024 23:55:44 -0500 Subject: [PATCH 3/4] feat: TryInto trait bound for uri::Builder --- src/uri/builder.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/uri/builder.rs b/src/uri/builder.rs index 9964d389..126b357f 100644 --- a/src/uri/builder.rs +++ b/src/uri/builder.rs @@ -1,4 +1,4 @@ -use std::convert::{TryFrom, TryInto}; +use std::convert::TryInto; use super::{Authority, Parts, PathAndQuery, Scheme}; use crate::Uri; @@ -44,8 +44,8 @@ impl Builder { /// ``` pub fn scheme(self, scheme: T) -> Self where - Scheme: TryFrom, - >::Error: Into, + T: TryInto, + >::Error: Into, { self.map(move |mut parts| { let scheme = scheme.try_into().map_err(Into::into)?; @@ -68,8 +68,8 @@ impl Builder { /// ``` pub fn authority(self, auth: T) -> Self where - Authority: TryFrom, - >::Error: Into, + T: TryInto, + >::Error: Into, { self.map(move |mut parts| { let auth = auth.try_into().map_err(Into::into)?; @@ -92,8 +92,8 @@ impl Builder { /// ``` pub fn path_and_query(self, p_and_q: T) -> Self where - PathAndQuery: TryFrom, - >::Error: Into, + T: TryInto, + >::Error: Into, { self.map(move |mut parts| { let p_and_q = p_and_q.try_into().map_err(Into::into)?; From dc17be54ef1a88e301708d1146ef1d770452c099 Mon Sep 17 00:00:00 2001 From: rob Date: Thu, 28 Nov 2024 00:53:42 -0500 Subject: [PATCH 4/4] chore: format files --- src/request.rs | 22 +++++++++++----------- src/response.rs | 14 +++++++------- src/uri/builder.rs | 8 ++++---- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/request.rs b/src/request.rs index ee9d94a6..324b676c 100644 --- a/src/request.rs +++ b/src/request.rs @@ -231,7 +231,7 @@ impl Request<()> { /// ``` pub fn get(uri: T) -> Builder where - T: TryInto, + T: TryInto, >::Error: Into, { Builder::new().method(Method::GET).uri(uri) @@ -253,7 +253,7 @@ impl Request<()> { /// ``` pub fn put(uri: T) -> Builder where - T: TryInto, + T: TryInto, >::Error: Into, { Builder::new().method(Method::PUT).uri(uri) @@ -275,7 +275,7 @@ impl Request<()> { /// ``` pub fn post(uri: T) -> Builder where - T: TryInto, + T: TryInto, >::Error: Into, { Builder::new().method(Method::POST).uri(uri) @@ -297,7 +297,7 @@ impl Request<()> { /// ``` pub fn delete(uri: T) -> Builder where - T: TryInto, + T: TryInto, >::Error: Into, { Builder::new().method(Method::DELETE).uri(uri) @@ -321,7 +321,7 @@ impl Request<()> { pub fn options(uri: T) -> Builder where T: TryInto, - >::Error: Into + >::Error: Into, { Builder::new().method(Method::OPTIONS).uri(uri) } @@ -343,7 +343,7 @@ impl Request<()> { pub fn head(uri: T) -> Builder where T: TryInto, - >::Error: Into + >::Error: Into, { Builder::new().method(Method::HEAD).uri(uri) } @@ -365,7 +365,7 @@ impl Request<()> { pub fn connect(uri: T) -> Builder where T: TryInto, - >::Error: Into + >::Error: Into, { Builder::new().method(Method::CONNECT).uri(uri) } @@ -387,7 +387,7 @@ impl Request<()> { pub fn patch(uri: T) -> Builder where T: TryInto, - >::Error: Into + >::Error: Into, { Builder::new().method(Method::PATCH).uri(uri) } @@ -409,7 +409,7 @@ impl Request<()> { pub fn trace(uri: T) -> Builder where T: TryInto, - >::Error: Into + >::Error: Into, { Builder::new().method(Method::TRACE).uri(uri) } @@ -768,7 +768,7 @@ impl Builder { pub fn method(self, method: T) -> Builder where T: TryInto, - >::Error: Into + >::Error: Into, { self.and_then(move |mut head| { let method = method.try_into().map_err(Into::into)?; @@ -813,7 +813,7 @@ impl Builder { pub fn uri(self, uri: T) -> Builder where T: TryInto, - >::Error: Into + >::Error: Into, { self.and_then(move |mut head| { head.uri = uri.try_into().map_err(Into::into)?; diff --git a/src/response.rs b/src/response.rs index 01f7e3d1..ab9e49bc 100644 --- a/src/response.rs +++ b/src/response.rs @@ -68,7 +68,7 @@ use std::fmt; use crate::header::{HeaderMap, HeaderName, HeaderValue}; use crate::status::StatusCode; use crate::version::Version; -use crate::{ Extensions, Result}; +use crate::{Extensions, Result}; /// Represents an HTTP response /// @@ -559,8 +559,8 @@ impl Builder { /// ``` pub fn status(self, status: T) -> Builder where - T: TryInto, - >::Error: Into, + T: TryInto, + >::Error: Into, { self.and_then(move |mut head| { head.status = status.try_into().map_err(Into::into)?; @@ -610,10 +610,10 @@ impl Builder { /// ``` pub fn header(self, key: K, value: V) -> Builder where - K: TryInto, - >::Error: Into, - V: TryInto, - >::Error: Into, + K: TryInto, + >::Error: Into, + V: TryInto, + >::Error: Into, { self.and_then(move |mut head| { let name = key.try_into().map_err(Into::into)?; diff --git a/src/uri/builder.rs b/src/uri/builder.rs index 126b357f..d5f7f49b 100644 --- a/src/uri/builder.rs +++ b/src/uri/builder.rs @@ -44,8 +44,8 @@ impl Builder { /// ``` pub fn scheme(self, scheme: T) -> Self where - T: TryInto, - >::Error: Into, + T: TryInto, + >::Error: Into, { self.map(move |mut parts| { let scheme = scheme.try_into().map_err(Into::into)?; @@ -68,7 +68,7 @@ impl Builder { /// ``` pub fn authority(self, auth: T) -> Self where - T: TryInto, + T: TryInto, >::Error: Into, { self.map(move |mut parts| { @@ -92,7 +92,7 @@ impl Builder { /// ``` pub fn path_and_query(self, p_and_q: T) -> Self where - T: TryInto, + T: TryInto, >::Error: Into, { self.map(move |mut parts| {