1use serde::{de, ser};
8use std::fmt::{self, Display};
9
10#[derive(Debug, thiserror::Error)]
12pub enum Error {
13 #[error("{0}")]
15 Message(String),
16
17 #[error("unexpected end of input")]
19 Eof,
20
21 #[error("invalid bool encoding: {0}")]
23 InvalidBool(u8),
24
25 #[error("invalid option tag: {0}")]
27 InvalidOptionTag(u8),
28
29 #[error("invalid utf-8 while decoding")]
31 InvalidUtf8,
32
33 #[error("invalid char encoding")]
35 InvalidChar,
36
37 #[error("deserialize_any is not supported by the fixint format")]
40 NotSupported,
41
42 #[error("{0} trailing byte(s) after decoded value")]
44 TrailingBytes(usize),
45}
46
47pub type Result<T> = std::result::Result<T, Error>;
49
50impl ser::Error for Error {
51 fn custom<T: Display>(msg: T) -> Self {
52 Error::Message(msg.to_string())
53 }
54}
55
56impl de::Error for Error {
57 fn custom<T: Display>(msg: T) -> Self {
58 Error::Message(msg.to_string())
59 }
60}
61
62impl From<fmt::Error> for Error {
63 fn from(_: fmt::Error) -> Self {
64 Error::Message("formatting error".to_string())
65 }
66}