-#[derive(Debug)]
-struct Error {
- message: String
-}
-
-impl std::fmt::Display for Error {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- f.write_str(&self.message)
- }
-}
-
-impl std::error::Error for Error { }
-
-#[derive(Debug, Deserialize, Serialize)]
-struct Config {
- delay_between_check: time::Duration,
- api_key: String,
- domains: Vec<String>,
-}
-
-impl Config {
- fn default() -> Self {
- Config { delay_between_check: time::Duration::from_secs(60), api_key: String::from(""), domains: Vec::new() }
- }
-
- fn read(file_path: &str) -> Result<Config> {
- match File::open(file_path) {
- Ok(file) => from_reader(file).map_err(|e| e.into()),
- // The file doesn't exit -> create it with default values.
- Err(_) => {
- let file = File::create(file_path)?;
- let default_config = Config::default();
- to_writer(file, &default_config)?;
- Ok(default_config)
- }
- }
- }
-}
+use crate::error::{ Result, Error };
+use crate::config::Config;