epee_serde/
error.rs

1use std::fmt::Display;
2use std::io;
3
4use serde::{de, ser};
5use thiserror::Error;
6
7use crate::Marker;
8
9pub type Result<T> = std::result::Result<T, Error>;
10
11#[derive(Debug, Error)]
12pub enum Error {
13    #[error("Io error: {0}")]
14    Io(#[from] io::Error),
15    #[error("Invalid Bool value")]
16    InvalidBoolValue,
17    #[error("Invalid Varint mask")]
18    InvalidVarIntMask,
19    #[error("Value Marked As String Exceeded Max Length")]
20    MarkedStringExceededMaxLength,
21    #[error("Invalid String")]
22    InvalidString,
23    #[error("Invalid Marker: {0}")]
24    UnknownMarker(Marker),
25    #[error("Unexpected Marker: {0}")]
26    UnexpectedMarker(String),
27    #[error("Length Mismatch: {0}")]
28    LengthMismatch(String),
29    #[error("Tuples Of Type {0} Not Supported")]
30    TuplesOfTypeNotSupported(Marker),
31    #[error("Tuple Structs Not Supported")]
32    TupleStructsNotSupported,
33    #[error("Missing Header")]
34    MissingHeader,
35    #[error("Invalid Portable Storage Version: {0}")]
36    InvalidVersion(u8),
37    #[error("Root must be struct")]
38    RootValueIsNotStruct,
39    #[error("f32 Not supported")]
40    F32NotSupported,
41    #[error("Options Not supported")]
42    OptionsNotSupported,
43    #[error("Unit Not supported")]
44    UnitNotSupported,
45    #[error("Enums Not supported")]
46    EnumNotSupported,
47    #[error("Length of Seq/Maps Must Be Known Ahead Of Time")]
48    UnknownLength,
49    #[error("{0}")]
50    Custom(String),
51}
52
53impl de::Error for Error {
54    fn custom<T: Display>(msg: T) -> Self {
55        Error::Custom(msg.to_string())
56    }
57}
58
59impl ser::Error for Error {
60    fn custom<T>(msg: T) -> Self
61    where
62        T: Display,
63    {
64        Error::Custom(msg.to_string())
65    }
66}