1use std::fmt::{self, Display};
16
17use serde::{de, ser};
18
19#[derive(Debug)]
20pub enum Error {
21 Message(String),
22 ExpectedMapEq,
23 ExpectedInteger,
24 ExpectedFloat,
25 ExpectedBool,
26 ExpectedUnit,
27 Trailing(String),
28 Ignored(String),
29 IdNotFound(String),
30 Overflow,
31 UnknownType,
32}
33
34impl std::error::Error for Error {}
35
36impl Display for Error {
37 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38 write!(f, "{self:?}")
39 }
40}
41
42impl de::Error for Error {
43 fn custom<T>(msg: T) -> Self
44 where
45 T: Display,
46 {
47 Error::Message(msg.to_string())
48 }
49}
50
51impl ser::Error for Error {
52 fn custom<T>(msg: T) -> Self
53 where
54 T: Display,
55 {
56 Error::Message(msg.to_string())
57 }
58}
59
60pub type Result<T, E = Error> = std::result::Result<T, E>;