diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 6 | ||||
| -rw-r--r-- | src/main.rs | 4 |
2 files changed, 8 insertions, 2 deletions
@@ -12,6 +12,12 @@ pub struct Config { pub printers: Vec<Printer>, } +impl Config { + pub fn load(toml: &str) -> Config { + toml::from_str(toml).expect("Couldn't parse config.toml") + } +} + #[derive(Debug, Deserialize)] #[serde(tag = "type", rename_all = "lowercase")] pub enum Printer { diff --git a/src/main.rs b/src/main.rs index 7660108..4fbd24a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,10 +9,10 @@ use tokio::sync::Mutex; #[tokio::main] async fn main() { let content = fs::read_to_string("config.toml").expect("Couldn't read config.toml"); - let config: Config = toml::from_str(&content).expect("Couldn't parse config.toml"); + let config = Config::load(&content); let state = Arc::new(Mutex::new(HashMap::<String, PrinterState>::new())); - for printer in &config.printers { + for printer in config.printers { match printer { Printer::Prusa { name, host, .. } => { println!("Found Prusa: {} at {}", name, host); |
