1use serde_core::{de, ser};
2use std::fmt;
3use thiserror::Error;
4
5#[derive(Debug, Error)]
6pub enum Error {
7 #[error("serialization error: {0}")]
8 Serialization(String),
9
10 #[error("deserialization error: {0}")]
11 Deserialization(String),
12
13 #[error("invalid type: {message}")]
14 InvalidType { message: String },
15
16 #[error("invalid value for {typ}: {value}")]
17 InvalidValue { typ: String, value: String },
18
19 #[error("unsupported feature: {0}")]
20 UnsupportedFeature(String),
21
22 #[error("missing field: {0}")]
23 MissingField(String),
24
25 #[error("error while unescaping: {0}")]
26 Unescape(String),
27
28 #[error("custom error: {0}")]
29 Custom(String),
30}
31
32impl ser::Error for Error {
33 fn custom<T: fmt::Display>(msg: T) -> Self {
34 Error::Custom(msg.to_string())
35 }
36}
37
38impl de::Error for Error {
39 fn custom<T: fmt::Display>(msg: T) -> Self {
40 Error::Custom(msg.to_string())
41 }
42}
43
44pub type Result<T> = std::result::Result<T, Error>;