serde_cqcode/
err.rs

1use std::num::{ParseFloatError, ParseIntError};
2
3#[derive(Debug, Clone, thiserror::Error)]
4pub enum Error {
5    #[error("unsupported type: {0}")]
6    UnsupportedType(String),
7    #[error(transparent)]
8    ParseIntError(#[from] ParseIntError),
9    #[error(transparent)]
10    ParseFloatError(#[from] ParseFloatError),
11    #[error("expected cq code")]
12    ExpectedCQCode,
13    #[error("mismatched value: expected {1}, found {0}")]
14    MismatchedValueType(String, String),
15    #[error("missing cq code type")]
16    MissingCodeType,
17    #[error("missing value")]
18    MissingValue,
19    #[error("expected delimiter")]
20    ExpectedDelimiter,
21    #[error("expected cq code type")]
22    ExpectedCodeType,
23    #[error("expected code comma")]
24    ExpectedCodeComma,
25    #[error("expected code colon")]
26    ExpectedCodeColon,
27    #[error("expected code start")]
28    ExpectedCodeStart,
29    #[error("expected code end")]
30    ExpectedCodeEnd,
31    #[error("unknown escaping")]
32    UnknownEscaping(String),
33    #[error("expected value type {1}, found value {0}")]
34    UnknownValue(String, String),
35    #[error("end of input")]
36    Eof,
37    #[error("{0}")]
38    Custom(String),
39}
40
41impl serde::de::Error for Error {
42    fn custom<T>(msg: T) -> Self
43    where
44        T: std::fmt::Display,
45    {
46        Self::Custom(msg.to_string())
47    }
48}
49
50impl serde::ser::Error for Error {
51    fn custom<T>(msg: T) -> Self
52    where
53        T: std::fmt::Display,
54    {
55        Self::Custom(msg.to_string())
56    }
57}