From 197280fe3e75d6f205887ecd5fbb249cc8cda5f4 Mon Sep 17 00:00:00 2001 From: Glenn Griffin Date: Tue, 10 Dec 2019 14:06:15 -0800 Subject: [PATCH] Rename the type parameter from C to M for mappers. --- src/mappers.rs | 62 ++++++++++++++++++++--------------------- src/mappers/request.rs | 60 +++++++++++++++++++-------------------- src/mappers/response.rs | 36 ++++++++++++------------ src/mappers/sequence.rs | 8 +++--- 4 files changed, 83 insertions(+), 83 deletions(-) diff --git a/src/mappers.rs b/src/mappers.rs index 51e1a32..0008d0b 100644 --- a/src/mappers.rs +++ b/src/mappers.rs @@ -96,20 +96,20 @@ where } /// Call Deref::deref() on the input and pass it to the next mapper. -pub fn deref(inner: C) -> Deref { +pub fn deref(inner: M) -> Deref { Deref(inner) } /// The `Deref` mapper returned by [deref()](fn.deref.html) #[derive(Debug)] -pub struct Deref(C); -impl Mapper for Deref +pub struct Deref(M); +impl Mapper for Deref where - C: Mapper, + M: Mapper, IN: std::ops::Deref, { - type Out = C::Out; + type Out = M::Out; - fn map(&mut self, input: &IN) -> C::Out { + fn map(&mut self, input: &IN) -> M::Out { self.0.map(input.deref()) } } @@ -162,14 +162,14 @@ where } /// invert the result of the inner mapper. -pub fn not(inner: C) -> Not { +pub fn not(inner: M) -> Not { Not(inner) } /// The `Not` mapper returned by [not()](fn.not.html) -pub struct Not(C); -impl Mapper for Not +pub struct Not(M); +impl Mapper for Not where - C: Mapper, + M: Mapper, IN: ?Sized, { type Out = bool; @@ -178,9 +178,9 @@ where !self.0.map(input) } } -impl fmt::Debug for Not +impl fmt::Debug for Not where - C: fmt::Debug, + M: fmt::Debug, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Not({:?})", &self.0) @@ -237,20 +237,20 @@ where } /// url decode the input and pass the resulting slice of key-value pairs to the next mapper. -pub fn url_decoded(inner: C) -> UrlDecoded { +pub fn url_decoded(inner: M) -> UrlDecoded { UrlDecoded(inner) } /// The `UrlDecoded` mapper returned by [url_decoded()](fn.url_decoded.html) #[derive(Debug)] -pub struct UrlDecoded(C); -impl Mapper for UrlDecoded +pub struct UrlDecoded(M); +impl Mapper for UrlDecoded where IN: AsRef<[u8]> + ?Sized, - C: Mapper<[(String, String)]>, + M: Mapper<[(String, String)]>, { - type Out = C::Out; + type Out = M::Out; - fn map(&mut self, input: &IN) -> C::Out { + fn map(&mut self, input: &IN) -> M::Out { let decoded: Vec<(String, String)> = url::form_urlencoded::parse(input.as_ref()) .into_owned() .collect(); @@ -263,20 +263,20 @@ where /// /// If the input can't be decoded a serde_json::Value::Null is passed to the next /// mapper. -pub fn json_decoded(inner: C) -> JsonDecoded { +pub fn json_decoded(inner: M) -> JsonDecoded { JsonDecoded(inner) } /// The `JsonDecoded` mapper returned by [json_decoded()](fn.json_decoded.html) #[derive(Debug)] -pub struct JsonDecoded(C); -impl Mapper for JsonDecoded +pub struct JsonDecoded(M); +impl Mapper for JsonDecoded where IN: AsRef<[u8]> + ?Sized, - C: Mapper, + M: Mapper, { - type Out = C::Out; + type Out = M::Out; - fn map(&mut self, input: &IN) -> C::Out { + fn map(&mut self, input: &IN) -> M::Out { let json_value: serde_json::Value = serde_json::from_slice(input.as_ref()).unwrap_or(serde_json::Value::Null); self.0.map(&json_value) @@ -284,23 +284,23 @@ where } /// lowercase the input and pass it to the next mapper. -pub fn lowercase(inner: C) -> Lowercase +pub fn lowercase(inner: M) -> Lowercase where - C: Mapper<[u8]>, + M: Mapper<[u8]>, { Lowercase(inner) } /// The `Lowercase` mapper returned by [lowercase()](fn.lowercase.html) #[derive(Debug)] -pub struct Lowercase(C); -impl Mapper for Lowercase +pub struct Lowercase(M); +impl Mapper for Lowercase where IN: AsRef<[u8]> + ?Sized, - C: Mapper<[u8]>, + M: Mapper<[u8]>, { - type Out = C::Out; + type Out = M::Out; - fn map(&mut self, input: &IN) -> C::Out { + fn map(&mut self, input: &IN) -> M::Out { use bstr::ByteSlice; self.0.map(&input.as_ref().to_lowercase()) } diff --git a/src/mappers/request.rs b/src/mappers/request.rs index 5f3c95a..21e51fe 100644 --- a/src/mappers/request.rs +++ b/src/mappers/request.rs @@ -3,74 +3,74 @@ use super::Mapper; /// Extract the method from the HTTP request and pass it to the next mapper. -pub fn method(inner: C) -> Method { +pub fn method(inner: M) -> Method { Method(inner) } /// The `Method` mapper returned by [method()](fn.method.html) #[derive(Debug)] -pub struct Method(C); -impl Mapper> for Method +pub struct Method(M); +impl Mapper> for Method where - C: Mapper, + M: Mapper, { - type Out = C::Out; + type Out = M::Out; - fn map(&mut self, input: &hyper::Request) -> C::Out { + fn map(&mut self, input: &hyper::Request) -> M::Out { self.0.map(input.method().as_str()) } } /// Extract the path from the HTTP request and pass it to the next mapper. -pub fn path(inner: C) -> Path { +pub fn path(inner: M) -> Path { Path(inner) } /// The `Path` mapper returned by [path()](fn.path.html) #[derive(Debug)] -pub struct Path(C); -impl Mapper> for Path +pub struct Path(M); +impl Mapper> for Path where - C: Mapper, + M: Mapper, { - type Out = C::Out; + type Out = M::Out; - fn map(&mut self, input: &hyper::Request) -> C::Out { + fn map(&mut self, input: &hyper::Request) -> M::Out { self.0.map(input.uri().path()) } } /// Extract the query from the HTTP request and pass it to the next mapper. -pub fn query(inner: C) -> Query { +pub fn query(inner: M) -> Query { Query(inner) } /// The `Query` mapper returned by [query()](fn.query.html) #[derive(Debug)] -pub struct Query(C); -impl Mapper> for Query +pub struct Query(M); +impl Mapper> for Query where - C: Mapper, + M: Mapper, { - type Out = C::Out; + type Out = M::Out; - fn map(&mut self, input: &hyper::Request) -> C::Out { + fn map(&mut self, input: &hyper::Request) -> M::Out { self.0.map(input.uri().query().unwrap_or("")) } } /// Extract the headers from the HTTP request and pass the sequence to the next /// mapper. -pub fn headers(inner: C) -> Headers { +pub fn headers(inner: M) -> Headers { Headers(inner) } /// The `Headers` mapper returned by [headers()](fn.headers.html) #[derive(Debug)] -pub struct Headers(C); -impl Mapper> for Headers +pub struct Headers(M); +impl Mapper> for Headers where - C: Mapper<[(Vec, Vec)]>, + M: Mapper<[(Vec, Vec)]>, { - type Out = C::Out; + type Out = M::Out; - fn map(&mut self, input: &hyper::Request) -> C::Out { + fn map(&mut self, input: &hyper::Request) -> M::Out { let headers: Vec<(Vec, Vec)> = input .headers() .iter() @@ -81,20 +81,20 @@ where } /// Extract the body from the HTTP request and pass it to the next mapper. -pub fn body(inner: C) -> Body { +pub fn body(inner: M) -> Body { Body(inner) } /// The `Body` mapper returned by [body()](fn.body.html) #[derive(Debug)] -pub struct Body(C); -impl Mapper> for Body +pub struct Body(M); +impl Mapper> for Body where B: ToOwned, - C: Mapper, + M: Mapper, { - type Out = C::Out; + type Out = M::Out; - fn map(&mut self, input: &hyper::Request) -> C::Out { + fn map(&mut self, input: &hyper::Request) -> M::Out { self.0.map(&input.body().to_owned()) } } diff --git a/src/mappers/response.rs b/src/mappers/response.rs index 8deec74..169d76d 100644 --- a/src/mappers/response.rs +++ b/src/mappers/response.rs @@ -3,38 +3,38 @@ use super::Mapper; /// Extract the status code from the HTTP response and pass it to the next mapper. -pub fn status_code(inner: C) -> StatusCode { +pub fn status_code(inner: M) -> StatusCode { StatusCode(inner) } /// The `StatusCode` mapper returned by [status_code()](fn.status_code.html) #[derive(Debug)] -pub struct StatusCode(C); -impl Mapper> for StatusCode +pub struct StatusCode(M); +impl Mapper> for StatusCode where - C: Mapper, + M: Mapper, { - type Out = C::Out; + type Out = M::Out; - fn map(&mut self, input: &hyper::Response) -> C::Out { + fn map(&mut self, input: &hyper::Response) -> M::Out { self.0.map(&input.status().as_u16()) } } /// Extract the headers from the HTTP response and pass the sequence to the next /// mapper. -pub fn headers(inner: C) -> Headers { +pub fn headers(inner: M) -> Headers { Headers(inner) } /// The `Headers` mapper returned by [headers()](fn.headers.html) #[derive(Debug)] -pub struct Headers(C); -impl Mapper> for Headers +pub struct Headers(M); +impl Mapper> for Headers where - C: Mapper<[(Vec, Vec)]>, + M: Mapper<[(Vec, Vec)]>, { - type Out = C::Out; + type Out = M::Out; - fn map(&mut self, input: &hyper::Response) -> C::Out { + fn map(&mut self, input: &hyper::Response) -> M::Out { let headers: Vec<(Vec, Vec)> = input .headers() .iter() @@ -45,19 +45,19 @@ where } /// Extract the body from the HTTP response and pass it to the next mapper. -pub fn body(inner: C) -> Body { +pub fn body(inner: M) -> Body { Body(inner) } /// The `Body` mapper returned by [body()](fn.body.html) #[derive(Debug)] -pub struct Body(C); -impl Mapper> for Body +pub struct Body(M); +impl Mapper> for Body where - C: Mapper, + M: Mapper, { - type Out = C::Out; + type Out = M::Out; - fn map(&mut self, input: &hyper::Response) -> C::Out { + fn map(&mut self, input: &hyper::Response) -> M::Out { self.0.map(input.body()) } } diff --git a/src/mappers/sequence.rs b/src/mappers/sequence.rs index 9efeeb8..d31ef90 100644 --- a/src/mappers/sequence.rs +++ b/src/mappers/sequence.rs @@ -4,15 +4,15 @@ use super::Mapper; /// true if the provided mapper returns true for any of the elements in the /// sequence. -pub fn contains(inner: C) -> Contains { +pub fn contains(inner: M) -> Contains { Contains(inner) } /// The `Contains` mapper returned by [contains()](fn.contains.html) #[derive(Debug)] -pub struct Contains(C); -impl Mapper<[E]> for Contains +pub struct Contains(M); +impl Mapper<[E]> for Contains where - C: Mapper, + M: Mapper, { type Out = bool;