diff options
Diffstat (limited to 'src/error.rs')
| -rw-r--r-- | src/error.rs | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/src/error.rs b/src/error.rs deleted file mode 100644 index b7866d7..0000000 --- a/src/error.rs +++ /dev/null | |||
| @@ -1,55 +0,0 @@ | |||
| 1 | use std::error::Error; | ||
| 2 | use std::fmt::Display; | ||
| 3 | use std::io; | ||
| 4 | |||
| 5 | pub type ArchiveResult<T, E> = Result<T, ArchiveError<E>>; | ||
| 6 | |||
| 7 | #[derive(Debug)] | ||
| 8 | pub enum ArchiveError<E: Error> { | ||
| 9 | Io { error: io::Error }, | ||
| 10 | Serde { message: String }, | ||
| 11 | Archivator { module: &'static str, error: E }, | ||
| 12 | } | ||
| 13 | |||
| 14 | impl<E: Error> From<io::Error> for ArchiveError<E> { | ||
| 15 | fn from(value: io::Error) -> Self { | ||
| 16 | Self::Io { error: value } | ||
| 17 | } | ||
| 18 | } | ||
| 19 | |||
| 20 | impl<E: Error + PartialEq> PartialEq<E> for ArchiveError<E> { | ||
| 21 | fn eq(&self, other: &E) -> bool { | ||
| 22 | match self { | ||
| 23 | Self::Archivator { error, .. } => error == other, | ||
| 24 | _ => false, | ||
| 25 | } | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | impl<E: Error> Display for ArchiveError<E> { | ||
| 30 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| 31 | match self { | ||
| 32 | Self::Io { error } => writeln!(f, "IO: {error}"), | ||
| 33 | Self::Serde { message } => writeln!(f, "Serde: {message}"), | ||
| 34 | Self::Archivator { module, error } => writeln!(f, "{module}: {error}"), | ||
| 35 | } | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | impl<E: Error> Error for ArchiveError<E> {} | ||
| 40 | |||
| 41 | impl<E: Error> serde::ser::Error for ArchiveError<E> { | ||
| 42 | fn custom<T: Display>(msg: T) -> Self { | ||
| 43 | Self::Serde { | ||
| 44 | message: msg.to_string(), | ||
| 45 | } | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | impl<E: Error> serde::de::Error for ArchiveError<E> { | ||
| 50 | fn custom<T: Display>(msg: T) -> Self { | ||
| 51 | Self::Serde { | ||
| 52 | message: msg.to_string(), | ||
| 53 | } | ||
| 54 | } | ||
| 55 | } | ||
