Add initial (#1)

This commit is contained in:
Dave Gallant
2020-06-21 02:20:36 -04:00
committed by GitHub
parent 966478aece
commit d6c5b13f67
13 changed files with 2133 additions and 1 deletions

40
src/config.rs Normal file
View File

@@ -0,0 +1,40 @@
extern crate toml;
use serde_derive::Deserialize;
use std::fs;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parse_config() {
let file = "./examples/config.toml";
parse(&file);
}
}
#[derive(Deserialize, Debug)]
pub struct Config {
pub expressions: Vec<String>,
pub sendgrid: Sendgrid,
}
#[derive(Deserialize, Debug)]
pub struct Sendgrid {
pub mail_from: String,
pub mail_to: String,
pub api_key: String,
}
pub fn parse(filename: &str) -> Config {
let contents = fs::read_to_string(filename)
.unwrap_or_else(|e| panic!("Unable to read configuration file '{}'. {}", filename, e));
let config: Config = toml::from_str(&contents).unwrap_or_else(|e| {
panic!(
"Unable to parse configuration with contents: {}. {}",
contents, e
)
});
config
}