serde_test/
error.rs

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