aboutsummaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
authorIgor Tolmachev <me@igorek.dev>2024-07-20 16:52:39 +0900
committerIgor Tolmachev <me@igorek.dev>2024-07-20 16:52:39 +0900
commit7bcdc3b4ca460aec2b98fb2dca6165788c562b05 (patch)
tree63f9616fc1b7f9ca6e414a4d32910720e155690c /src/error.rs
parent5f4ceda88c7299deb317f8d22a99ab2521c5a380 (diff)
downloadarchivator-7bcdc3b4ca460aec2b98fb2dca6165788c562b05.tar.gz
archivator-7bcdc3b4ca460aec2b98fb2dca6165788c562b05.zip
Partial aes implementation and others improvements
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs55
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 @@
1use std::error::Error;
2use std::fmt::Display;
3use std::io;
4
5pub type ArchiveResult<T, E> = Result<T, ArchiveError<E>>;
6
7#[derive(Debug)]
8pub enum ArchiveError<E: Error> {
9 Io { error: io::Error },
10 Serde { message: String },
11 Archivator { module: &'static str, error: E },
12}
13
14impl<E: Error> From<io::Error> for ArchiveError<E> {
15 fn from(value: io::Error) -> Self {
16 Self::Io { error: value }
17 }
18}
19
20impl<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
29impl<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
39impl<E: Error> Error for ArchiveError<E> {}
40
41impl<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
49impl<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}