1pub mod json_parser;
2pub mod toml_parser;
3pub mod yaml_parser;
4
5pub enum SupportedFiles {
6 Json,
7 Toml,
8 Yaml,
9}
10
11impl SupportedFiles {
12 pub fn maybe_from_str(input: &str) -> Option<SupportedFiles> {
13 match input {
14 "json" => Some(SupportedFiles::Json),
15 "toml" => Some(SupportedFiles::Toml),
16 "yaml" => Some(SupportedFiles::Yaml),
17 _ => None,
18 }
19 }
20}
21
22#[derive(Debug)]
23pub enum TError {
24 NoInput,
25 KeyNotExist(String),
26 ConversionError(String, Box<dyn std::error::Error>),
27 Other(Box<dyn std::error::Error>),
28}
29
30impl std::error::Error for TError {}
31
32impl std::fmt::Display for TError {
33 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34 write!(f, "{:#?}", self)
35 }
36}
37
38macro_rules! impl_error {
39 ($ty:ty) => {
40 impl std::convert::From<$ty> for TError {
41 fn from(err: $ty) -> Self {
42 TError::Other(Box::new(err))
43 }
44 }
45 };
46}
47
48impl_error!(std::num::ParseIntError);
49impl_error!(serde_json::Error);
50impl_error!(serde_yaml::Error);
51impl_error!(toml::de::Error);
52impl_error!(std::io::Error);
53
54trait Solver {
55 fn solve(input: &str, expression: Option<&str>) -> String;
56}