2017-01-11 02:39:16 -08:00
|
|
|
use std::error;
|
|
|
|
use std::fmt::{self, Display};
|
2016-06-28 21:47:54 -07:00
|
|
|
|
2017-12-23 20:13:08 -08:00
|
|
|
use serde::{de, ser};
|
2016-06-28 21:47:54 -07:00
|
|
|
|
2017-04-19 11:38:57 -07:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct Error {
|
|
|
|
msg: String,
|
2016-06-28 21:47:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ser::Error for Error {
|
2017-11-06 22:31:35 -08:00
|
|
|
fn custom<T: Display>(msg: T) -> Self {
|
2017-12-23 20:13:08 -08:00
|
|
|
Error {
|
|
|
|
msg: msg.to_string(),
|
|
|
|
}
|
2016-06-28 21:47:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl de::Error for Error {
|
2017-11-06 22:31:35 -08:00
|
|
|
fn custom<T: Display>(msg: T) -> Self {
|
2017-12-23 20:13:08 -08:00
|
|
|
Error {
|
|
|
|
msg: msg.to_string(),
|
|
|
|
}
|
2016-06-28 21:47:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for Error {
|
2017-01-11 02:39:16 -08:00
|
|
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
2017-04-19 11:38:57 -07:00
|
|
|
formatter.write_str(&self.msg)
|
2016-06-28 21:47:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl error::Error for Error {
|
|
|
|
fn description(&self) -> &str {
|
2017-04-19 11:38:57 -07:00
|
|
|
&self.msg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialEq<str> for Error {
|
|
|
|
fn eq(&self, other: &str) -> bool {
|
|
|
|
self.msg == other
|
2016-06-28 21:47:54 -07:00
|
|
|
}
|
|
|
|
}
|