pax_designtime/serde_pax/
error.rs1use std;
2use std::fmt::{self, Display};
3
4use serde::{de, ser};
5
6pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Debug)]
13pub enum Error {
14 Message(String),
20
21 UnsupportedType(String),
25 TrailingCharacters,
26 UnsupportedMethod,
27}
28
29impl ser::Error for Error {
30 fn custom<T: Display>(msg: T) -> Self {
31 Error::Message(msg.to_string())
32 }
33}
34
35impl de::Error for Error {
36 fn custom<T: Display>(msg: T) -> Self {
37 Error::Message(msg.to_string())
38 }
39}
40
41impl Display for Error {
42 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
43 match self {
44 Error::Message(msg) => formatter.write_str(msg),
45 Error::UnsupportedType(t) => {
46 formatter.write_str(format!("unsupported type: {}", t).as_str())
47 }
48 Error::TrailingCharacters => {
49 formatter.write_str("trailing characters after deserialization")
50 }
51 _ => formatter.write_str("unknown error"),
52 }
53 }
54}
55
56impl std::error::Error for Error {}