Skip to content

Commit

Permalink
Processed feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorKoenders committed Jan 19, 2022
1 parent e9fce58 commit 89b482b
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions src/features/serde/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub use self::ser::*;

/// A serde-specific error that occured while decoding.
#[derive(Debug, PartialEq)]
#[non_exhaustive]
pub enum DecodeError {
/// Bincode does not support serde's `any` decoding feature
AnyNotSupported,
Expand All @@ -98,6 +99,30 @@ pub enum DecodeError {
CustomError,
}

#[cfg(feature = "alloc")]
impl serde_incl::de::Error for crate::error::DecodeError {
fn custom<T>(msg: T) -> Self
where
T: core::fmt::Display,
{
use alloc::string::ToString;
Self::OtherString(msg.to_string())
}
}

#[cfg(not(feature = "std"))]
impl serde_incl::de::StdError for crate::error::DecodeError {}

#[cfg(not(feature = "alloc"))]
impl serde_incl::de::Error for crate::error::DecodeError {
fn custom<T>(_: T) -> Self
where
T: core::fmt::Display,
{
DecodeError::CustomError.into()
}
}

#[allow(clippy::from_over_into)]
impl Into<crate::error::DecodeError> for DecodeError {
fn into(self) -> crate::error::DecodeError {
Expand All @@ -107,6 +132,7 @@ impl Into<crate::error::DecodeError> for DecodeError {

/// A serde-specific error that occured while encoding.
#[derive(Debug, PartialEq)]
#[non_exhaustive]
pub enum EncodeError {
/// Serde provided bincode with a sequence without a length, which is not supported in bincode
SequenceMustHaveLength,
Expand All @@ -127,30 +153,6 @@ impl Into<crate::error::EncodeError> for EncodeError {
}
}

#[cfg(feature = "alloc")]
impl serde_incl::de::Error for crate::error::DecodeError {
fn custom<T>(msg: T) -> Self
where
T: core::fmt::Display,
{
use alloc::string::ToString;
Self::OtherString(msg.to_string())
}
}

#[cfg(not(feature = "std"))]
impl serde_incl::de::StdError for crate::error::DecodeError {}

#[cfg(not(feature = "alloc"))]
impl serde_incl::de::Error for crate::error::DecodeError {
fn custom<T>(_: T) -> Self
where
T: core::fmt::Display,
{
DecodeError::CustomError.into()
}
}

#[cfg(feature = "alloc")]
impl serde_incl::ser::Error for crate::error::EncodeError {
fn custom<T>(msg: T) -> Self
Expand Down

0 comments on commit 89b482b

Please sign in to comment.