diff options
Diffstat (limited to 'src/result.rs')
| -rw-r--r-- | src/result.rs | 63 |
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 @@ | |||
| 1 | use std::error::Error; | ||
| 2 | use std::fmt::{Debug, Display}; | ||
| 3 | use std::io; | ||
| 4 | |||
| 5 | pub type ArchiveResult<R> = Result<R, ArchiveError>; | ||
| 6 | |||
| 7 | #[derive(Debug)] | ||
| 8 | pub 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 | |||
| 18 | impl From<io::Error> for ArchiveError { | ||
| 19 | fn from(value: io::Error) -> Self { | ||
| 20 | Self::IO(value) | ||
| 21 | } | ||
| 22 | } | ||
| 23 | |||
| 24 | impl 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 | |||
| 56 | impl 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 | } | ||
