1 use serde::{de, ser}; 2 use std::error; 3 use std::fmt::{self, Display}; 4 5 #[derive(Clone, Debug)] 6 pub struct Error { 7 msg: String, 8 } 9 10 impl ser::Error for Error { custom<T: Display>(msg: T) -> Self11 fn custom<T: Display>(msg: T) -> Self { 12 Error { 13 msg: msg.to_string(), 14 } 15 } 16 } 17 18 impl de::Error for Error { custom<T: Display>(msg: T) -> Self19 fn custom<T: Display>(msg: T) -> Self { 20 Error { 21 msg: msg.to_string(), 22 } 23 } 24 } 25 26 impl fmt::Display for Error { fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result27 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { 28 formatter.write_str(&self.msg) 29 } 30 } 31 32 impl error::Error for Error { description(&self) -> &str33 fn description(&self) -> &str { 34 &self.msg 35 } 36 } 37 38 impl PartialEq<str> for Error { eq(&self, other: &str) -> bool39 fn eq(&self, other: &str) -> bool { 40 self.msg == other 41 } 42 } 43