1use core::fmt::{Display, Formatter};
16
17#[derive(Clone, Debug, Eq, PartialEq)]
20pub enum Error {
21    DeserializeBadBool,
23    DeserializeBadChar,
24    DeserializeBadOption,
25    DeserializeBadUtf8,
26    DeserializeUnexpectedEnd,
27    NotSupported,
28    SerializeBufferFull,
29}
30
31pub type Result<T> = core::result::Result<T, Error>;
32
33impl Display for Error {
34    fn fmt(&self, formatter: &mut Formatter) -> core::fmt::Result {
35        formatter.write_str(match self {
36            Self::DeserializeBadBool => "Found a bool that wasn't 0 or 1",
38            Self::DeserializeBadChar => "Found an invalid unicode char",
39            Self::DeserializeBadOption => "Found an Option discriminant that wasn't 0 or 1",
40            Self::DeserializeBadUtf8 => "Tried to parse invalid utf-8",
41            Self::DeserializeUnexpectedEnd => "Unexpected end during deserialization",
42            Self::NotSupported => "Not supported",
43            Self::SerializeBufferFull => "The serialize buffer is full",
44        })
45    }
46}
47
48impl serde::ser::Error for Error {
49    fn custom<T: Display>(_msg: T) -> Self {
50        Error::NotSupported
52    }
53}
54
55impl serde::de::Error for Error {
56    fn custom<T: Display>(_msg: T) -> Self {
57        Error::NotSupported
59    }
60}
61
62impl serde::ser::StdError for Error {}