use serde::de;
use std::{error, fmt};
pub type DeResult<T> = ::std::result::Result<T, DeError>;
#[derive(Clone, Debug, PartialEq)]
pub enum DeError {
Message(String),
UnknownField,
InvalidType(String),
UnsupportedType,
}
impl de::Error for DeError {
fn custom<T: fmt::Display>(msg: T) -> Self {
DeError::Message(msg.to_string())
}
}
impl fmt::Display for DeError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let msg = match self {
DeError::Message(ref msg) => msg,
DeError::UnknownField => "Unknown field",
DeError::InvalidType(_) => "Invalid type",
DeError::UnsupportedType => "Type unsupported",
};
f.write_str(msg)
}
}
impl error::Error for DeError {}