1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8pub type ParseError = Error;
10pub type FileError = Error;
11
12#[derive(Error, Debug)]
14pub enum Error {
15 #[error("YINI Parse Error: {message}")]
17 ParseError { message: String },
18
19 #[error("YINI File Error: {message}")]
21 FileError { message: String },
22
23 #[error("Type conversion error: {message}")]
25 TypeError { message: String },
26
27 #[error("Key not found: {key}")]
29 KeyNotFound { key: String },
30
31 #[error("Section not found: {name}")]
33 SectionNotFound { name: String },
34}
35
36impl Error {
37 pub fn parse_error(message: impl Into<String>) -> Self {
39 Self::ParseError {
40 message: message.into(),
41 }
42 }
43
44 pub fn file_error(message: impl Into<String>) -> Self {
46 Self::FileError {
47 message: message.into(),
48 }
49 }
50
51 pub fn type_error(message: impl Into<String>) -> Self {
53 Self::TypeError {
54 message: message.into(),
55 }
56 }
57
58 pub fn key_not_found(key: impl Into<String>) -> Self {
60 Self::KeyNotFound { key: key.into() }
61 }
62
63 pub fn section_not_found(name: impl Into<String>) -> Self {
65 Self::SectionNotFound { name: name.into() }
66 }
67}
68
69impl From<std::io::Error> for Error {
70 fn from(err: std::io::Error) -> Self {
71 Self::FileError {
72 message: err.to_string(),
73 }
74 }
75}