xml_rpc/xmlfmt/
error.rs

1#![allow(unknown_lints, unused_doc_comments)]
2use serde::{de, ser};
3use std::fmt::{self, Display};
4
5error_chain! {
6    foreign_links {
7        Fmt(fmt::Error);
8    }
9
10    errors {
11        Decoding(t: String) {
12            description("Issue while decoding data structure")
13            display("Issue while decoding data structure: {}", t)
14        }
15        Encoding(t: String) {
16            description("Issue while encoding data structure")
17            display("Issue while encoding data structure: {}", t)
18        }
19        UnsupportedData(t: String) {
20            description("Given structure is not supported")
21            display("Given structure is not supported: {}", t)
22        }
23    }
24}
25
26impl de::Error for Error {
27    fn custom<T: Display>(msg: T) -> Error {
28        ErrorKind::Decoding(format!("{}", msg)).into()
29    }
30
31    fn invalid_type(unexp: de::Unexpected, exp: &dyn de::Expected) -> Self {
32        Error::custom(format_args!("invalid type: {}, expected {}", unexp, exp))
33    }
34}
35
36impl ser::Error for Error {
37    fn custom<T: Display>(msg: T) -> Error {
38        ErrorKind::Encoding(format!("{}", msg)).into()
39    }
40}