• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use std::error;
2 use std::fmt::{self, Display};
3 
4 use serde::{de, ser};
5 
6 #[derive(Clone, Debug)]
7 pub struct Error {
8     msg: String,
9 }
10 
11 impl ser::Error for Error {
custom<T: Display>(msg: T) -> Self12     fn custom<T: Display>(msg: T) -> Self {
13         Error {
14             msg: msg.to_string(),
15         }
16     }
17 }
18 
19 impl de::Error for Error {
custom<T: Display>(msg: T) -> Self20     fn custom<T: Display>(msg: T) -> Self {
21         Error {
22             msg: msg.to_string(),
23         }
24     }
25 }
26 
27 impl fmt::Display for Error {
fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result28     fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
29         formatter.write_str(&self.msg)
30     }
31 }
32 
33 impl error::Error for Error {
description(&self) -> &str34     fn description(&self) -> &str {
35         &self.msg
36     }
37 }
38 
39 impl PartialEq<str> for Error {
eq(&self, other: &str) -> bool40     fn eq(&self, other: &str) -> bool {
41         self.msg == other
42     }
43 }
44