1pub type Result<T> = std::result::Result<T, Error>;
2
3#[derive(Debug, thiserror::Error)]
4pub enum Error {
5 #[error("Unsupported operation {0}")]
6 Unsupported(&'static str),
7 #[error("Expected {expected} but got {but_got}")]
8 Unexpected {
9 expected: &'static str,
10 but_got: String,
11 },
12 #[error(
13 "In '{element_name}', attribute '{attribute_name}' comes after at least one element. All attributes must come before any elements."
14 )]
15 AttributesMustComeBeforeElements {
16 element_name: String,
17 attribute_name: &'static str,
18 },
19 #[error("Custom: {0}")]
20 Custom(String),
21 #[error("Reader: {0}")]
22 Reader(#[from] xml::reader::Error),
23 #[error("Writer: {0}")]
24 Writer(#[from] xml::writer::Error),
25 #[error("UTF-8: {0}")]
26 FromUtf8(#[from] std::string::FromUtf8Error),
27 #[error("Parse: {0}")]
28 ParseBool(#[from] std::str::ParseBoolError),
29 #[error("Parse int: {0}")]
30 ParseInt(#[from] std::num::ParseIntError),
31 #[error("Parse float: {0}")]
32 ParseFloat(#[from] std::num::ParseFloatError),
33}
34
35impl serde::de::Error for Error {
36 fn custom<T>(msg: T) -> Self
37 where
38 T: std::fmt::Display,
39 {
40 Self::Custom(msg.to_string())
41 }
42}
43
44impl serde::ser::Error for Error {
45 fn custom<T>(msg: T) -> Self
46 where
47 T: std::fmt::Display,
48 {
49 Self::Custom(msg.to_string())
50 }
51}