aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-03-26 13:04:28 +0200
committerHampusM <hampus@hampusmat.com>2023-03-26 13:04:28 +0200
commitc8e5944d697b33738c7ba01694dde5e360470043 (patch)
treec7ba2ec7b2c381adfae2a42c2ced46ba0fbd07a4 /src
parentadd06dafdf874b1b419e5eef918c6b1131ab09fd (diff)
refactor: add deserializer error wrapper
Diffstat (limited to 'src')
-rw-r--r--src/command.rs31
-rw-r--r--src/lib.rs15
2 files changed, 42 insertions, 4 deletions
diff --git a/src/command.rs b/src/command.rs
index 2ba92ea..5d3c935 100644
--- a/src/command.rs
+++ b/src/command.rs
@@ -9,6 +9,7 @@ use crate::deserialization::{
IgnoreEnd,
ResultExt,
};
+use crate::DeserializationError;
/// A command.
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -88,7 +89,15 @@ pub enum Error
/// Deserialization failed.
#[error("Deserialization failed")]
- DeserializationFailed(#[from] DeserializerError),
+ DeserializationFailed(#[from] DeserializationError),
+}
+
+impl From<DeserializerError> for Error
+{
+ fn from(err: DeserializerError) -> Self
+ {
+ DeserializationError(err).into()
+ }
}
/// A command prototype.
@@ -160,7 +169,15 @@ pub enum PrototypeError
/// Deserialization failed.
#[error("Deserialization failed")]
- DeserializationFailed(#[from] DeserializerError),
+ DeserializationFailed(#[from] DeserializationError),
+}
+
+impl From<DeserializerError> for PrototypeError
+{
+ fn from(err: DeserializerError) -> Self
+ {
+ DeserializationError(err).into()
+ }
}
/// A command parameter.
@@ -228,7 +245,15 @@ pub enum ParameterError
/// Deserialization failed.
#[error("Deserialization failed")]
- DeserializationFailed(#[from] DeserializerError),
+ DeserializationFailed(#[from] DeserializationError),
+}
+
+impl From<DeserializerError> for ParameterError
+{
+ fn from(err: DeserializerError) -> Self
+ {
+ DeserializationError(err).into()
+ }
}
fn deserialize_type<Err>(deserializer: &mut impl Deserializer) -> Result<String, Err>
diff --git a/src/lib.rs b/src/lib.rs
index f3bbc54..68af8ae 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -153,5 +153,18 @@ pub enum RegistryError
/// Deserialization failed.
#[error("Deserialization failed")]
- DeserializationFailed(#[from] DeserializerError),
+ DeserializationFailed(#[from] DeserializationError),
}
+
+impl From<DeserializerError> for RegistryError
+{
+ fn from(err: DeserializerError) -> Self
+ {
+ DeserializationError(err).into()
+ }
+}
+
+/// Deserialization error.
+#[derive(Debug, thiserror::Error)]
+#[error(transparent)]
+pub struct DeserializationError(#[from] DeserializerError);