aboutsummaryrefslogtreecommitdiff
path: root/src/structs/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/structs/error.rs
parent5f4ceda88c7299deb317f8d22a99ab2521c5a380 (diff)
downloadarchivator-7bcdc3b4ca460aec2b98fb2dca6165788c562b05.tar.gz
archivator-7bcdc3b4ca460aec2b98fb2dca6165788c562b05.zip
Partial aes implementation and others improvements
Diffstat (limited to 'src/structs/error.rs')
-rw-r--r--src/structs/error.rs41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/structs/error.rs b/src/structs/error.rs
index f07163c..deb10b3 100644
--- a/src/structs/error.rs
+++ b/src/structs/error.rs
@@ -1,37 +1,42 @@
1use crate::{ArchiveError, ArchiveResult}; 1use serde::{de, ser};
2use std::error::Error; 2use std::error::Error;
3use std::fmt::Display; 3use std::fmt::Display;
4 4
5pub type StructResult<T> = ArchiveResult<T, StructError>; 5pub type StructResult<T> = Result<T, StructError>;
6 6
7#[derive(Debug)] 7#[derive(Debug, PartialEq, Eq)]
8pub enum StructError { 8pub enum StructError {
9 SerializationNotSupported { type_name: &'static str }, 9 SerializationNotSupported(&'static str),
10 DeserializationNotSupported { type_name: &'static str }, 10 DeserializationNotSupported(&'static str),
11 Serde(String),
11 UnexpectedEOF, 12 UnexpectedEOF,
12} 13}
13 14
14impl From<StructError> for ArchiveError<StructError> {
15 fn from(value: StructError) -> Self {
16 Self::Archivator {
17 module: "Struct serializer",
18 error: value,
19 }
20 }
21}
22
23impl Display for StructError { 15impl Display for StructError {
24 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 16 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25 match self { 17 match self {
26 Self::SerializationNotSupported { type_name } => { 18 Self::SerializationNotSupported(name) => {
27 writeln!(f, "Serialization for type '{type_name}' not supported") 19 writeln!(f, "Serialization for type '{}' not supported", name)
28 } 20 }
29 Self::DeserializationNotSupported { type_name } => { 21 Self::DeserializationNotSupported(name) => {
30 writeln!(f, "Deserialization for type '{type_name}' not supported") 22 writeln!(f, "Deserialization for type '{}' not supported", name)
31 } 23 }
24 Self::Serde(message) => writeln!(f, "Serde error: {}", message),
32 Self::UnexpectedEOF => writeln!(f, "Unexpected EOF"), 25 Self::UnexpectedEOF => writeln!(f, "Unexpected EOF"),
33 } 26 }
34 } 27 }
35} 28}
36 29
37impl Error for StructError {} 30impl Error for StructError {}
31
32impl ser::Error for StructError {
33 fn custom<T: Display>(msg: T) -> Self {
34 Self::Serde(msg.to_string())
35 }
36}
37
38impl de::Error for StructError {
39 fn custom<T: Display>(msg: T) -> Self {
40 Self::Serde(msg.to_string())
41 }
42}