use serde::{de, ser};
use std::fmt::{self, Display};
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("{0}")]
Message(String),
#[error("unexpected end of input")]
Eof,
#[error("invalid bool encoding: {0}")]
InvalidBool(u8),
#[error("invalid option tag: {0}")]
InvalidOptionTag(u8),
#[error("invalid utf-8 while decoding")]
InvalidUtf8,
#[error("invalid char encoding")]
InvalidChar,
#[error("deserialize_any is not supported by the fixint format")]
NotSupported,
#[error("{0} trailing byte(s) after decoded value")]
TrailingBytes(usize),
}
pub type Result<T> = std::result::Result<T, Error>;
impl ser::Error for Error {
fn custom<T: Display>(msg: T) -> Self {
Error::Message(msg.to_string())
}
}
impl de::Error for Error {
fn custom<T: Display>(msg: T) -> Self {
Error::Message(msg.to_string())
}
}
impl From<fmt::Error> for Error {
fn from(_: fmt::Error) -> Self {
Error::Message("formatting error".to_string())
}
}