v1.0.100
-
Provide
serde::ser::StdError
andserde::de::StdError
which are either a re-export ofstd::error::Error
(if Serde's "std" feature is enabled) or a new identical trait (otherwise).#[cfg(feature = "std")] pub use std::error::Error as StdError; #[cfg(not(feature = "std"))] pub trait StdError: Debug + Display { fn source(&self) -> Option<&(StdError + 'static)> { None } }
Serde's error traits
serde::ser::Error
andserde::de::Error
requirestd::error::Error
as a supertrait, but only when Serde is built with "std" enabled. Data formats that don't care about no_std support should generally provide their error types with astd::error::Error
impl directly:#[derive(Debug)] struct MySerError {...} impl serde::ser::Error for MySerError {...} impl std::fmt::Display for MySerError {...} // We don't support no_std! impl std::error::Error for MySerError {}
Data formats that do support no_std may either have a "std" feature of their own as has been required in the past:
[features] std = ["serde/std"]
#[cfg(feature = "std")] impl std::error::Error for MySerError {}
... or else now may provide the std Error impl unconditionally via Serde's re-export:
impl serde::ser::StdError for MySerError {}