use super::{super::super::std::immutable::*, body::*};
use {
http::response::*,
std::{error::*, fmt},
};
#[derive(Clone, Debug)]
pub struct ResponsePieces<ResponseBodyT> {
pub response: Response<ResponseBodyT>,
pub first_bytes: ImmutableBytes,
}
impl<ResponseBodyT> ResponsePieces<ResponseBodyT> {
pub fn new(parts: Parts, body: ResponseBodyT, first_bytes: ImmutableBytes) -> Self {
Self { response: Response::from_parts(parts, body), first_bytes }
}
pub fn new_from_body_pieces(parts: Parts, body_pieces: BodyPieces<ResponseBodyT>) -> Self {
Self::new(parts, body_pieces.body, body_pieces.first_bytes)
}
}
pub struct ErrorWithResponsePieces<ErrorT, BodyT> {
pub error: ErrorT,
pub pieces: Option<ResponsePieces<BodyT>>,
}
impl<ErrorT, BodyT> ErrorWithResponsePieces<ErrorT, BodyT> {
pub fn new(error: ErrorT, pieces: Option<ResponsePieces<BodyT>>) -> Self {
Self { error, pieces }
}
pub fn new_from_body(error: ErrorWithBodyPieces<ErrorT, BodyT>, parts: Parts) -> Self {
Self::new(error.error, error.pieces.map(|pieces| ResponsePieces::new_from_body_pieces(parts, pieces)))
}
}
impl<ErrorT, BodyT> fmt::Debug for ErrorWithResponsePieces<ErrorT, BodyT>
where
ErrorT: fmt::Debug,
{
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(&self.error, formatter)
}
}
impl<ErrorT, BodyT> fmt::Display for ErrorWithResponsePieces<ErrorT, BodyT>
where
ErrorT: fmt::Display,
{
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&self.error, formatter)
}
}
impl<ErrorT, BodyT> Error for ErrorWithResponsePieces<ErrorT, BodyT>
where
ErrorT: Error,
{
fn source(&self) -> Option<&(dyn Error + 'static)> {
self.error.source()
}
}
impl<ErrorT, BodyT> From<ErrorT> for ErrorWithResponsePieces<ErrorT, BodyT> {
fn from(error: ErrorT) -> Self {
Self::new(error, None)
}
}