keri_core/error/
serializer_error.rs1use std;
2use std::fmt::{self, Display};
3
4use serde::{de, ser, Deserialize, Serialize};
5
6pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
13pub enum Error {
14 Message(String),
20
21 Eof,
25 Syntax,
26 ExpectedBoolean,
27 ExpectedInteger,
28 ExpectedString,
29 ExpectedNull,
30 ExpectedArray,
31 ExpectedArrayComma,
32 ExpectedArrayEnd,
33 ExpectedMap,
34 ExpectedMapColon,
35 ExpectedMapComma,
36 ExpectedMapEnd,
37 ExpectedEnum,
38 TrailingCharacters,
39}
40
41impl ser::Error for Error {
42 fn custom<T: Display>(msg: T) -> Self {
43 Error::Message(msg.to_string())
44 }
45}
46
47impl de::Error for Error {
48 fn custom<T: Display>(msg: T) -> Self {
49 Error::Message(msg.to_string())
50 }
51}
52
53impl Display for Error {
54 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
55 match self {
56 Error::Message(msg) => formatter.write_str(msg),
57 Error::Eof => formatter.write_str("unexpected end of input"),
58 Error::Syntax => formatter.write_str("incorrect syntax"),
59 Error::ExpectedBoolean => formatter.write_str("incorrect input: expected boolean"),
60 Error::ExpectedInteger => formatter.write_str("incorrect input: expected integer"),
61 Error::ExpectedString => formatter.write_str("incorrect input: expected string"),
62 Error::ExpectedNull => formatter.write_str("incorrect input: expected null"),
63 Error::ExpectedArray => formatter.write_str("incorrect input: expected array"),
64 Error::ExpectedArrayComma => {
65 formatter.write_str("incorrect input: expected array comma")
66 }
67 Error::ExpectedArrayEnd => formatter.write_str("incorrect input: expected array end"),
68 Error::ExpectedMap => formatter.write_str("incorrect input: expected map"),
69 Error::ExpectedMapColon => formatter.write_str("incorrect input: expected map colon"),
70 Error::ExpectedMapComma => formatter.write_str("incorrect input: expected map comma"),
71 Error::ExpectedMapEnd => formatter.write_str("incorrect input: expected map end"),
72 Error::ExpectedEnum => formatter.write_str("incorrect input: expected enum"),
73 Error::TrailingCharacters => {
74 formatter.write_str("incorrect input: unexpected trailing characters")
75 }
76 }
77 }
78}
79
80impl std::error::Error for Error {}