erased_serde/
error.rs

1use crate::alloc::{String, ToString};
2use core::fmt::{self, Display};
3
4/// Error when a `Serializer` or `Deserializer` trait object fails.
5#[derive(Debug)]
6pub struct Error {
7    msg: String,
8}
9
10/// Result type alias where the error is `erased_serde::Error`.
11pub type Result<T> = core::result::Result<T, Error>;
12
13impl Display for Error {
14    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
15        self.msg.fmt(formatter)
16    }
17}
18
19impl serde::ser::StdError for Error {}
20
21impl serde::ser::Error for Error {
22    fn custom<T: Display>(msg: T) -> Self {
23        Error {
24            msg: msg.to_string(),
25        }
26    }
27}
28
29impl serde::de::Error for Error {
30    fn custom<T: Display>(msg: T) -> Self {
31        Error {
32            msg: msg.to_string(),
33        }
34    }
35}