use std::fmt::{self, Display};
use serde::{de, ser};
#[derive(Debug)]
pub enum Error {
Message(String),
ExpectedMapEq,
ExpectedInteger,
ExpectedFloat,
ExpectedBool,
ExpectedUnit,
Trailing(String),
Ignored(String),
IdNotFound(String),
Overflow,
UnknownType,
}
impl std::error::Error for Error {}
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{self:?}")
}
}
impl de::Error for Error {
fn custom<T>(msg: T) -> Self
where
T: Display,
{
Error::Message(msg.to_string())
}
}
impl ser::Error for Error {
fn custom<T>(msg: T) -> Self
where
T: Display,
{
Error::Message(msg.to_string())
}
}
pub type Result<T, E = Error> = std::result::Result<T, E>;