use super::super::super::std::immutable::*;
use std::{error::*, fmt};
#[derive(Clone, Debug)]
pub struct BodyPieces<BodyT> {
pub body: BodyT,
pub first_bytes: ImmutableBytes,
}
impl<BodyT> BodyPieces<BodyT> {
pub fn new(body: BodyT, first_bytes: ImmutableBytes) -> Self {
Self { body, first_bytes }
}
}
pub struct ErrorWithBodyPieces<ErrorT, BodyT> {
pub error: ErrorT,
pub pieces: Option<BodyPieces<BodyT>>,
}
impl<ErrorT, BodyT> ErrorWithBodyPieces<ErrorT, BodyT> {
pub fn new(error: ErrorT, pieces: Option<BodyPieces<BodyT>>) -> Self {
Self { error, pieces }
}
}
impl<ErrorT, BodyT> fmt::Debug for ErrorWithBodyPieces<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 ErrorWithBodyPieces<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 ErrorWithBodyPieces<ErrorT, BodyT>
where
ErrorT: Error,
{
fn source(&self) -> Option<&(dyn Error + 'static)> {
self.error.source()
}
}
impl<ErrorT, BodyT> From<ErrorT> for ErrorWithBodyPieces<ErrorT, BodyT> {
fn from(error: ErrorT) -> Self {
Self::new(error, None)
}
}