1use std::fmt::Display;
2use serde::{de, ser};
3use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
6
7#[derive(Error, Debug)]
8pub enum Error {
9 #[error("Message: {0}")]
10 Message(String),
11
12 #[error("Eof")]
13 Eof,
14
15 #[error("Expected string")]
16 ExpectedString,
17
18 #[error("Expected object start '{{'")]
19 ExpectedObjectStart,
20
21 #[error("Expected object end '}}'")]
22 ExpectedObjectEnd,
23
24 #[error("Expected key")]
25 ExpectedKey,
26
27 #[error("Expected value")]
28 ExpectedValue,
29
30 #[error("Trailing characters")]
31 TrailingCharacters,
32
33 #[error("Syntax error at line {line}, column {column}: {msg}")]
34 Syntax {
35 line: usize,
36 column: usize,
37 msg: String,
38 },
39
40 #[error("IO error: {0}")]
41 Io(#[from] std::io::Error),
42
43 #[error("Float parse error: {0}")]
44 FloatParse(#[from] std::num::ParseFloatError),
45
46 #[error("Int parse error: {0}")]
47 IntParse(#[from] std::num::ParseIntError),
48}
49
50impl ser::Error for Error {
51 fn custom<T: Display>(msg: T) -> Self {
52 Error::Message(msg.to_string())
53 }
54}
55
56impl de::Error for Error {
57 fn custom<T: Display>(msg: T) -> Self {
58 Error::Message(msg.to_string())
59 }
60}