archlinux_repo_parser/
error.rs1use std::fmt::{self, Display};
2
3use serde::{de, ser};
4
5pub type Result<T> = std::result::Result<T, Error>;
6
7#[derive(Clone, Debug, PartialEq)]
8pub enum Error {
9 Message(String),
10 Eof,
11 FieldNameUnexpectedWrapper(String),
12 DelimiterExpected,
13 IntegerError,
14 NotSupported,
15 DelimiterNotExpected,
16 CharOverflow,
17 TrailingCharacters,
18 StructExpected,
19}
20
21impl ser::Error for Error {
22 fn custom<T: Display>(msg: T) -> Self {
23 Error::Message(msg.to_string())
24 }
25}
26
27impl de::Error for Error {
28 fn custom<T: Display>(msg: T) -> Self {
29 Error::Message(msg.to_string())
30 }
31}
32
33impl Display for Error {
34 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
35 match self {
36 Error::Message(msg) => formatter.write_str(msg),
37 Error::Eof => formatter.write_str("unexpected end of input"),
38 Error::FieldNameUnexpectedWrapper(line) => formatter.write_str(&format!(
39 "unexpected field wrapper at line {}. Field should start and end with '%' symbol",
40 line
41 )),
42 Error::DelimiterExpected => formatter.write_str("delimiter expected"),
43 Error::IntegerError => formatter.write_str("cannot parse integer"),
44 Error::NotSupported => formatter.write_str("action not supported"),
45 Error::DelimiterNotExpected => formatter.write_str("delimiter not expected"),
46 Error::CharOverflow => formatter.write_str("char field must have only one letter"),
47 Error::TrailingCharacters => formatter.write_str("unexpected trailing characters"),
48 Error::StructExpected => formatter.write_str("expected struct type"),
49 }
50 }
51}
52
53impl std::error::Error for Error {}