diff options
| author | Igor Tolmachev <me@igorek.dev> | 2024-06-16 21:36:13 +0900 |
|---|---|---|
| committer | Igor Tolmachev <me@igorek.dev> | 2024-06-23 15:34:34 +0900 |
| commit | d6055b5ac4f3ff5016bc4881cf1cc109a22c40ba (patch) | |
| tree | 40a9044f923945e6effc13c627261630dddc574c /src/structs/error.rs | |
| parent | 6444bee8f3e188be014841ea8cd7cfb53eb03ed9 (diff) | |
| download | archivator-d6055b5ac4f3ff5016bc4881cf1cc109a22c40ba.tar.gz archivator-d6055b5ac4f3ff5016bc4881cf1cc109a22c40ba.zip | |
Implement serialize
Diffstat (limited to 'src/structs/error.rs')
| -rw-r--r-- | src/structs/error.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/structs/error.rs b/src/structs/error.rs new file mode 100644 index 0000000..b9d765d --- /dev/null +++ b/src/structs/error.rs | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | use crate::{ArchiveError, ArchiveResult}; | ||
| 2 | use std::error::Error; | ||
| 3 | use std::fmt::Display; | ||
| 4 | |||
| 5 | pub type StructResult<T> = ArchiveResult<T, StructError>; | ||
| 6 | |||
| 7 | #[derive(Debug)] | ||
| 8 | pub enum StructError { | ||
| 9 | IncorrectEnumVariant, | ||
| 10 | } | ||
| 11 | |||
| 12 | impl From<StructError> for ArchiveError<StructError> { | ||
| 13 | fn from(value: StructError) -> Self { | ||
| 14 | Self::Archivator { | ||
| 15 | module: "Struct serializer".to_string(), | ||
| 16 | error: value, | ||
| 17 | } | ||
| 18 | } | ||
| 19 | } | ||
| 20 | |||
| 21 | impl Display for StructError { | ||
| 22 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| 23 | match self { | ||
| 24 | StructError::IncorrectEnumVariant => write!(f, "Can't cast enum variant type"), | ||
| 25 | } | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | impl Error for StructError {} | ||
