serdebin/
error.rs

1use std::fmt::{Display, Formatter};
2
3#[derive(Debug)]
4pub enum SerializerError {
5    UnexpectedEOF,
6    InvalidData,
7    Custom(String),
8}
9
10impl Display for SerializerError {
11    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
12        write!(f, "{:?}", self)
13    }
14}
15
16impl std::error::Error for SerializerError {}
17
18impl serde::ser::Error for SerializerError {
19    fn custom<T>(msg: T) -> Self
20    where
21        T: Display,
22    {
23        Self::Custom(msg.to_string())
24    }
25}
26
27impl serde::de::Error for SerializerError {
28    fn custom<T>(msg: T) -> Self
29    where
30        T: Display,
31    {
32        Self::Custom(msg.to_string())
33    }
34}