1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
mod header;
mod parser;
mod section;
mod sub_section;
mod to_string;

pub use header::Header;
pub use parser::parse;
pub use section::Section;
pub use sub_section::{SubSection, SubSections};
pub use to_string::to_string;

use thiserror::Error as Error_;

#[derive(Error_, Debug)]
pub enum Error {
    #[error("invalid input: {message}")]
    InvalidInput { message: String, context: String },

    #[error("file was empty")]
    EmptyFile,
    #[error("key not found: {key}")]
    NotFound { key: String },
    #[error("cant parse integer")]
    CantParseInt {
        #[from]
        source: std::num::ParseIntError,
    },
    #[error("cant parse bool")]
    CantParseBool,
    #[error("cant parse float")]
    CantParseFloat {
        #[from]
        source: std::num::ParseFloatError,
    },
    #[error("container contains duplicate keys")]
    DuplicateKeys,
}

pub type Result<T> = std::result::Result<T, Error>;