diff options
| author | Igor Tolmachov <me@igorek.dev> | 2023-08-17 15:34:47 +0900 |
|---|---|---|
| committer | Igor Tolmachev <me@igorek.dev> | 2024-06-23 15:34:32 +0900 |
| commit | d8be93a740e8cc8103c4f9e260a62244eba1a6a4 (patch) | |
| tree | acc3b3b7f86fa3e2e4e8656d554efa62a24aa3f7 /src/result.rs | |
| parent | 22dad8c7431d0ca94acc51d161e7f4ad5a4b1f5d (diff) | |
| download | archivator-d8be93a740e8cc8103c4f9e260a62244eba1a6a4.tar.gz archivator-d8be93a740e8cc8103c4f9e260a62244eba1a6a4.zip | |
Add basic lib architecture
Diffstat (limited to 'src/result.rs')
| -rw-r--r-- | src/result.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/result.rs b/src/result.rs new file mode 100644 index 0000000..47302ae --- /dev/null +++ b/src/result.rs | |||
| @@ -0,0 +1,32 @@ | |||
| 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 | } | ||
| 11 | |||
| 12 | impl From<io::Error> for ArchiveError { | ||
| 13 | fn from(value: io::Error) -> Self { | ||
| 14 | Self::IO(value) | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | impl Display for ArchiveError { | ||
| 19 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| 20 | match self { | ||
| 21 | Self::IO(err) => write!(f, "{err}"), | ||
| 22 | } | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | impl Error for ArchiveError { | ||
| 27 | fn source(&self) -> Option<&(dyn Error + 'static)> { | ||
| 28 | match self { | ||
| 29 | Self::IO(source) => Some(source), | ||
| 30 | } | ||
| 31 | } | ||
| 32 | } | ||
