simplify into body calls

This commit is contained in:
Rob Ede 2021-11-30 23:21:55 +00:00
parent c3c59e40d1
commit 56bdb39215
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
4 changed files with 17 additions and 33 deletions

View File

@ -105,12 +105,8 @@ where
fn respond_to(self, req: &HttpRequest) -> HttpResponse<Self::Body> {
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<Self::Body> {
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()
}
}

View File

@ -152,13 +152,8 @@ where
fn respond_to(self, req: &HttpRequest) -> HttpResponse<Self::Body> {
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(),
}
}
}

View File

@ -189,14 +189,13 @@ impl<T: Serialize> Responder for Form<T> {
.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()
}
}
}
}

View File

@ -125,14 +125,13 @@ impl<T: Serialize> Responder for Json<T> {
.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()
}
}
}
}