aws_multipart_upload/codec/
error.rs1use std::convert::Infallible;
2use std::fmt::{Display, Formatter, Result};
3
4pub trait EncodeError: std::error::Error {
6 fn message(&self) -> String;
8
9 fn kind(&self) -> EncodeErrorKind;
11}
12
13#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
15pub enum EncodeErrorKind {
16 Io,
18 Data,
20 Eof,
22 #[default]
24 Unknown,
25}
26
27impl Display for EncodeErrorKind {
28 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
29 let x = match self {
30 Self::Io => "io",
31 Self::Data => "data",
32 Self::Eof => "eof",
33 Self::Unknown => "unknown",
34 };
35 write!(f, "{x}")
36 }
37}
38
39impl EncodeError for std::io::Error {
40 fn message(&self) -> String {
41 self.to_string()
42 }
43
44 fn kind(&self) -> EncodeErrorKind {
45 EncodeErrorKind::Io
46 }
47}
48
49impl EncodeError for Infallible {
50 fn message(&self) -> String {
51 "unbelievable".into()
52 }
53
54 fn kind(&self) -> EncodeErrorKind {
55 EncodeErrorKind::Unknown
56 }
57}
58
59impl EncodeError for serde_json::Error {
60 fn message(&self) -> String {
61 self.to_string()
62 }
63
64 fn kind(&self) -> EncodeErrorKind {
65 match self.classify() {
66 serde_json::error::Category::Data | serde_json::error::Category::Syntax => {
67 EncodeErrorKind::Data
68 }
69 serde_json::error::Category::Eof => EncodeErrorKind::Eof,
70 serde_json::error::Category::Io => EncodeErrorKind::Io,
71 }
72 }
73}