generalize impl Responder for HttpResponse

This commit is contained in:
Ali MJ Al-Nasrawy 2022-01-04 16:16:57 +03:00
parent 85c9b1a263
commit fb7938854d
2 changed files with 8 additions and 11 deletions

View File

@ -1,12 +1,9 @@
use actix_http::{
body::{EitherBody, MessageBody},
error::HttpError,
header::HeaderMap,
header::TryIntoHeaderPair,
body::EitherBody, error::HttpError, header::HeaderMap, header::TryIntoHeaderPair,
StatusCode,
};
use crate::{BoxError, HttpRequest, HttpResponse, Responder};
use crate::{HttpRequest, HttpResponse, Responder};
/// Allows overriding status code and headers for a [`Responder`].
///
@ -143,7 +140,6 @@ impl<R: Responder> CustomizeResponder<R> {
impl<T> Responder for CustomizeResponder<T>
where
T: Responder,
<T::Body as MessageBody>::Error: Into<BoxError>,
{
type Body = EitherBody<T::Body>;

View File

@ -7,7 +7,7 @@ use actix_http::{
};
use bytes::{Bytes, BytesMut};
use crate::{BoxError, Error, HttpRequest, HttpResponse, HttpResponseBuilder};
use crate::{Error, HttpRequest, HttpResponse, HttpResponseBuilder};
use super::CustomizeResponder;
@ -57,8 +57,11 @@ pub trait Responder {
}
}
impl Responder for HttpResponse {
type Body = BoxBody;
impl<B> Responder for HttpResponse<B>
where
B: MessageBody + 'static,
{
type Body = B;
#[inline]
fn respond_to(self, _: &HttpRequest) -> HttpResponse<Self::Body> {
@ -96,7 +99,6 @@ impl Responder for actix_http::ResponseBuilder {
impl<T> Responder for Option<T>
where
T: Responder,
<T::Body as MessageBody>::Error: Into<BoxError>,
{
type Body = EitherBody<T::Body>;
@ -111,7 +113,6 @@ where
impl<T, E> Responder for Result<T, E>
where
T: Responder,
<T::Body as MessageBody>::Error: Into<BoxError>,
E: Into<Error>,
{
type Body = EitherBody<T::Body>;