use std::error;
use std::fmt;
use std::fmt::Display;
use std::io;
use std::str;
use std::string;
use serde::de;
use serde::ser;
#[derive(Debug)]
pub struct Error {
msg: String,
}
pub type Result<T> = std::result::Result<T, Error>;
impl Error {
pub fn new<T: Display>(msg: T) -> Self {
Error {
msg: msg.to_string(),
}
}
}
impl error::Error for Error {
fn description(&self) -> &str {
&self.msg
}
}
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&self.msg)
}
}
impl ser::Error for Error {
fn custom<T: Display>(msg: T) -> Self {
Error::new(msg)
}
}
impl de::Error for Error {
fn custom<T: Display>(msg: T) -> Self {
Error::new(msg)
}
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Error::new(err)
}
}
impl From<str::Utf8Error> for Error {
fn from(err: str::Utf8Error) -> Self {
Error::new(err)
}
}
impl From<string::FromUtf8Error> for Error {
fn from(err: string::FromUtf8Error) -> Self {
Error::new(err)
}
}