kutil_http/pieces/
body.rs1use {
2 bytes::*,
3 std::{error::*, fmt},
4};
5
6#[derive(Clone, Debug)]
15pub struct BodyPieces<BodyT> {
16 pub body: BodyT,
18
19 pub first_bytes: Bytes,
21}
22
23impl<BodyT> BodyPieces<BodyT> {
24 pub fn new(body: BodyT, first_bytes: Bytes) -> Self {
26 Self { body, first_bytes }
27 }
28}
29
30pub struct ErrorWithBodyPieces<ErrorT, BodyT> {
36 pub error: ErrorT,
38
39 pub pieces: Option<BodyPieces<BodyT>>,
41}
42
43impl<ErrorT, BodyT> ErrorWithBodyPieces<ErrorT, BodyT> {
44 pub fn new(error: ErrorT, pieces: Option<BodyPieces<BodyT>>) -> Self {
46 Self { error, pieces }
47 }
48}
49
50impl<ErrorT, BodyT> fmt::Debug for ErrorWithBodyPieces<ErrorT, BodyT>
51where
52 ErrorT: fmt::Debug,
53{
54 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
55 fmt::Debug::fmt(&self.error, formatter)
56 }
57}
58
59impl<ErrorT, BodyT> fmt::Display for ErrorWithBodyPieces<ErrorT, BodyT>
60where
61 ErrorT: fmt::Display,
62{
63 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
64 fmt::Display::fmt(&self.error, formatter)
65 }
66}
67
68impl<ErrorT, BodyT> Error for ErrorWithBodyPieces<ErrorT, BodyT>
69where
70 ErrorT: Error,
71{
72 fn source(&self) -> Option<&(dyn Error + 'static)> {
73 self.error.source()
74 }
75}
76
77impl<ErrorT, BodyT> From<ErrorT> for ErrorWithBodyPieces<ErrorT, BodyT> {
78 fn from(error: ErrorT) -> Self {
79 Self::new(error, None)
80 }
81}