diff --git a/src/deser.rs b/src/deser.rs index b80c6af..e0bee7e 100644 --- a/src/deser.rs +++ b/src/deser.rs @@ -71,9 +71,9 @@ pub use self::bincode::Bincode; pub trait DeSerializer: std::default::Default + Send + Sync + Clone { - /// Serializes a given value to a String + /// Serializes a given value to a [`String`]. fn serialize(&self, val: &T) -> Result, failure::Error>; - /// Deserializes a String to a value + /// Deserializes a [`String`] to a value. fn deserialize(&self, s: R) -> Result; } @@ -81,7 +81,6 @@ pub trait DeSerializer: mod ron { use std::io::Read; - use failure::ResultExt; use serde::de::DeserializeOwned; use serde::Serialize; @@ -90,20 +89,17 @@ mod ron { use ron::ser::PrettyConfig; use crate::deser::DeSerializer; - use crate::error; - /// The Struct that allows you to use `ron` the Rusty Object Notation + /// The Struct that allows you to use `ron` the Rusty Object Notation. #[derive(Debug, Default, Clone)] pub struct Ron; impl DeSerializer for Ron { fn serialize(&self, val: &T) -> Result, failure::Error> { - Ok(to_ron_string(val, PrettyConfig::default()) - .map(String::into_bytes) - .context(error::RustbreakErrorKind::Serialization)?) + Ok(to_ron_string(val, PrettyConfig::default()).map(String::into_bytes)?) } fn deserialize(&self, s: R) -> Result { - Ok(from_ron_string(s).context(error::RustbreakErrorKind::Deserialization)?) + Ok(from_ron_string(s)?) } } } @@ -112,26 +108,22 @@ mod ron { mod yaml { use std::io::Read; - use failure::ResultExt; use serde::de::DeserializeOwned; use serde::Serialize; use serde_yaml::{from_reader as from_yaml_string, to_string as to_yaml_string}; use crate::deser::DeSerializer; - use crate::error; - /// The struct that allows you to use yaml + /// The struct that allows you to use yaml. #[derive(Debug, Default, Clone)] pub struct Yaml; impl DeSerializer for Yaml { fn serialize(&self, val: &T) -> Result, failure::Error> { - Ok(to_yaml_string(val) - .map(String::into_bytes) - .context(error::RustbreakErrorKind::Serialization)?) + Ok(to_yaml_string(val).map(String::into_bytes)?) } fn deserialize(&self, s: R) -> Result { - Ok(from_yaml_string(s).context(error::RustbreakErrorKind::Deserialization)?) + Ok(from_yaml_string(s)?) } } } @@ -141,12 +133,10 @@ mod bincode { use std::io::Read; use bincode::{deserialize_from, serialize}; - use failure::ResultExt; use serde::de::DeserializeOwned; use serde::Serialize; use crate::deser::DeSerializer; - use crate::error; /// The struct that allows you to use bincode #[derive(Debug, Default, Clone)] @@ -154,10 +144,10 @@ mod bincode { impl DeSerializer for Bincode { fn serialize(&self, val: &T) -> Result, failure::Error> { - Ok(serialize(val).context(error::RustbreakErrorKind::Serialization)?) + Ok(serialize(val)?) } fn deserialize(&self, s: R) -> Result { - Ok(deserialize_from(s).context(error::RustbreakErrorKind::Deserialization)?) + Ok(deserialize_from(s)?) } } }