amadeus_utils/vecpak/
error.rs1use serde::{de, ser};
2use std::fmt::{self, Display};
3
4pub type Result<T> = std::result::Result<T, Error>;
5
6#[derive(Debug)]
7pub enum Error {
8 Message(String),
9 Eof,
10 TrailingBytes,
11 InvalidTag,
12 InvalidLength,
13 InvalidUtf8,
14}
15
16impl ser::Error for Error {
17 fn custom<T: Display>(msg: T) -> Self {
18 Error::Message(msg.to_string())
19 }
20}
21
22impl de::Error for Error {
23 fn custom<T: Display>(msg: T) -> Self {
24 Error::Message(msg.to_string())
25 }
26}
27
28impl Display for Error {
29 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
30 match self {
31 Error::Message(msg) => write!(f, "{}", msg),
32 Error::Eof => write!(f, "unexpected end of input"),
33 Error::TrailingBytes => write!(f, "trailing bytes after value"),
34 Error::InvalidTag => write!(f, "invalid type tag"),
35 Error::InvalidLength => write!(f, "invalid length"),
36 Error::InvalidUtf8 => write!(f, "invalid UTF-8"),
37 }
38 }
39}
40
41impl std::error::Error for Error {}