1use std::fmt;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Debug, thiserror::Error)]
10pub enum Error {
11 #[error("{0}")]
13 Message(String),
14
15 #[error("unexpected end of input")]
17 Eof,
18
19 #[error("invalid boolean value: {0}")]
21 InvalidBool(u32),
22
23 #[error("invalid enum discriminant: {0}")]
25 InvalidEnumDiscriminant(i32),
26
27 #[error("invalid UTF-8 string")]
29 InvalidUtf8,
30
31 #[error("string length {0} exceeds maximum {1}")]
33 StringTooLong(usize, usize),
34
35 #[error("array length {0} exceeds maximum {1}")]
37 ArrayTooLong(usize, usize),
38
39 #[error("trailing data: {0} bytes remaining")]
41 TrailingData(usize),
42}
43
44impl serde::ser::Error for Error {
45 fn custom<T: fmt::Display>(msg: T) -> Self {
46 Error::Message(msg.to_string())
47 }
48}
49
50impl serde::de::Error for Error {
51 fn custom<T: fmt::Display>(msg: T) -> Self {
52 Error::Message(msg.to_string())
53 }
54}