From 56bdb39215db1845d4cb789d8a528e8bd81a3034 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 30 Nov 2021 23:21:55 +0000 Subject: [PATCH] simplify into body calls --- src/responder.rs | 19 +++++-------------- src/types/either.rs | 9 ++------- src/types/form.rs | 11 +++++------ src/types/json.rs | 11 +++++------ 4 files changed, 17 insertions(+), 33 deletions(-) diff --git a/src/responder.rs b/src/responder.rs index e3dbb8731..f89e49237 100644 --- a/src/responder.rs +++ b/src/responder.rs @@ -105,12 +105,8 @@ where fn respond_to(self, req: &HttpRequest) -> HttpResponse { match self { - Some(val) => val - .respond_to(req) - .map_body(|_, body| EitherBody::left(body)), - - None => HttpResponse::new(StatusCode::NOT_FOUND) - .map_body(|_, body| EitherBody::right(body)), + Some(val) => val.respond_to(req).map_into_left_body(), + None => HttpResponse::new(StatusCode::NOT_FOUND).map_into_right_body(), } } } @@ -125,13 +121,8 @@ where fn respond_to(self, req: &HttpRequest) -> HttpResponse { match self { - Ok(val) => val - .respond_to(req) - .map_body(|_, body| EitherBody::left(body)), - - Err(err) => { - HttpResponse::from_error(err.into()).map_body(|_, body| EitherBody::right(body)) - } + Ok(val) => val.respond_to(req).map_into_left_body(), + Err(err) => HttpResponse::from_error(err.into()).map_into_right_body(), } } } @@ -278,7 +269,7 @@ where res.headers_mut().insert(k, v); } - res.map_body(|_, body| EitherBody::left(body)) + res.map_into_left_body() } } diff --git a/src/types/either.rs b/src/types/either.rs index e4a322caa..3ed55b248 100644 --- a/src/types/either.rs +++ b/src/types/either.rs @@ -152,13 +152,8 @@ where fn respond_to(self, req: &HttpRequest) -> HttpResponse { match self { - Either::Left(a) => a - .respond_to(req) - .map_body(|_, body| body::EitherBody::left(body)), - - Either::Right(b) => b - .respond_to(req) - .map_body(|_, body| body::EitherBody::right(body)), + Either::Left(a) => a.respond_to(req).map_into_left_body(), + Either::Right(b) => b.respond_to(req).map_into_right_body(), } } } diff --git a/src/types/form.rs b/src/types/form.rs index 3603ca2dd..9c09c6b73 100644 --- a/src/types/form.rs +++ b/src/types/form.rs @@ -189,14 +189,13 @@ impl Responder for Form { .content_type(mime::APPLICATION_WWW_FORM_URLENCODED) .message_body(body) { - Ok(res) => res.map_body(|_, body| EitherBody::left(body)), - Err(err) => { - HttpResponse::from_error(err).map_body(|_, body| EitherBody::right(body)) - } + Ok(res) => res.map_into_left_body(), + Err(err) => HttpResponse::from_error(err).map_into_right_body(), }, - Err(err) => HttpResponse::from_error(UrlencodedError::Serialize(err)) - .map_body(|_, body| EitherBody::right(body)), + Err(err) => { + HttpResponse::from_error(UrlencodedError::Serialize(err)).map_into_right_body() + } } } } diff --git a/src/types/json.rs b/src/types/json.rs index 568cf70fb..2b4d220e2 100644 --- a/src/types/json.rs +++ b/src/types/json.rs @@ -125,14 +125,13 @@ impl Responder for Json { .content_type(mime::APPLICATION_JSON) .message_body(body) { - Ok(res) => res.map_body(|_, body| EitherBody::left(body)), - Err(err) => { - HttpResponse::from_error(err).map_body(|_, body| EitherBody::right(body)) - } + Ok(res) => res.map_into_left_body(), + Err(err) => HttpResponse::from_error(err).map_into_right_body(), }, - Err(err) => HttpResponse::from_error(JsonPayloadError::Serialize(err)) - .map_body(|_, body| EitherBody::right(body)), + Err(err) => { + HttpResponse::from_error(JsonPayloadError::Serialize(err)).map_into_right_body() + } } } }