aboutsummaryrefslogtreecommitdiff
path: root/src/result.rs
diff options
context:
space:
mode:
authorIgor Tolmachev <me@igorek.dev>2024-06-10 23:38:08 +0900
committerIgor Tolmachev <me@igorek.dev>2024-06-23 15:34:34 +0900
commitbd77f62e99a5300dfa52aef3a7040414b28ebfd6 (patch)
tree4965b7fc0392264f9a8c44c00ed254019747b4b5 /src/result.rs
parent9003b81813ff171edfc6101868c226c5c7d1957c (diff)
downloadarchivator-bd77f62e99a5300dfa52aef3a7040414b28ebfd6.tar.gz
archivator-bd77f62e99a5300dfa52aef3a7040414b28ebfd6.zip
Reset branch
Diffstat (limited to 'src/result.rs')
-rw-r--r--src/result.rs63
1 files changed, 0 insertions, 63 deletions
diff --git a/src/result.rs b/src/result.rs
deleted file mode 100644
index 9f35920..0000000
--- a/src/result.rs
+++ /dev/null
@@ -1,63 +0,0 @@
1use std::error::Error;
2use std::fmt::{Debug, Display};
3use std::io;
4
5pub type ArchiveResult<R> = Result<R, ArchiveError>;
6
7#[derive(Debug)]
8pub enum ArchiveError {
9 IO(io::Error),
10 BadArchive { reason: &'static str },
11 IncorrectSignature { expected: u32, received: u32 },
12 IncorrectString { location: &'static str },
13 IncorrectDate { year: u16, month: u16, day: u16 },
14 IncorrectTime { hour: u16, min: u16, sec: u16 },
15 UnsupportedCompressionMethod { method: u16 },
16}
17
18impl From<io::Error> for ArchiveError {
19 fn from(value: io::Error) -> Self {
20 Self::IO(value)
21 }
22}
23
24impl Display for ArchiveError {
25 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26 match self {
27 Self::IO(err) => write!(f, "{err}"),
28 Self::BadArchive { reason } => {
29 write!(f, "Bad archive because {reason}")
30 }
31 Self::IncorrectSignature { expected, received } => {
32 write!(
33 f,
34 "Wrong signature (expected: {expected}, received: {received})"
35 )
36 }
37 Self::IncorrectString { location } => {
38 write!(f, "Incorrect string in {location}")
39 }
40 Self::IncorrectDate { year, month, day } => {
41 write!(
42 f,
43 "Incorrect date (year: {year}, month: {month}, day: {day})"
44 )
45 }
46 Self::IncorrectTime { hour, min, sec } => {
47 write!(f, "Incorrect time (hour: {hour}, min: {min}, sec: {sec})")
48 }
49 Self::UnsupportedCompressionMethod { method } => {
50 write!(f, "Unsupported compression method (method: {method})")
51 }
52 }
53 }
54}
55
56impl Error for ArchiveError {
57 fn source(&self) -> Option<&(dyn Error + 'static)> {
58 match self {
59 Self::IO(source) => Some(source),
60 _ => None,
61 }
62 }
63}