Implement core::error::Error for error types. (#780)
This commit is contained in:
parent
5a8ff74ab0
commit
6c1b0cd2c7
21
src/error.rs
21
src/error.rs
|
|
@ -63,6 +63,27 @@ impl core::fmt::Display for EncodeError {
|
|||
}
|
||||
}
|
||||
|
||||
impl core::error::Error for EncodeError {
|
||||
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
|
||||
match self {
|
||||
Self::RefCellAlreadyBorrowed { inner, .. } => Some(inner),
|
||||
#[cfg(feature = "std")]
|
||||
Self::Io { inner, .. } => Some(inner),
|
||||
#[cfg(feature = "std")]
|
||||
Self::InvalidSystemTime { inner, .. } => Some(inner),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl core::error::Error for DecodeError {
|
||||
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
|
||||
match self {
|
||||
Self::Utf8 { inner } => Some(inner),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Errors that can be encountered by decoding a type
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug)]
|
||||
|
|
|
|||
|
|
@ -412,25 +412,6 @@ impl<Context> Decode<Context> for SocketAddrV6 {
|
|||
}
|
||||
impl_borrow_decode!(SocketAddrV6);
|
||||
|
||||
impl std::error::Error for EncodeError {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
Self::RefCellAlreadyBorrowed { inner, .. } => Some(inner),
|
||||
Self::Io { inner, .. } => Some(inner),
|
||||
Self::InvalidSystemTime { inner, .. } => Some(inner),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl std::error::Error for DecodeError {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
Self::Utf8 { inner } => Some(inner),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V, S> Encode for HashMap<K, V, S>
|
||||
where
|
||||
K: Encode,
|
||||
|
|
|
|||
|
|
@ -114,9 +114,6 @@ impl serde::de::Error for crate::error::DecodeError {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
impl serde::de::StdError for crate::error::DecodeError {}
|
||||
|
||||
#[cfg(not(feature = "alloc"))]
|
||||
impl serde::de::Error for crate::error::DecodeError {
|
||||
fn custom<T>(_: T) -> Self
|
||||
|
|
@ -169,9 +166,6 @@ impl serde::ser::Error for crate::error::EncodeError {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
impl serde::de::StdError for crate::error::EncodeError {}
|
||||
|
||||
#[cfg(not(feature = "alloc"))]
|
||||
impl serde::ser::Error for crate::error::EncodeError {
|
||||
fn custom<T>(_: T) -> Self
|
||||
|
|
|
|||
Loading…
Reference in New Issue