From d76e080841e31eee9e882a22acc560c66e8a3ea9 Mon Sep 17 00:00:00 2001 From: Noah Swerhun Date: Tue, 5 Mar 2024 10:37:16 -0600 Subject: [PATCH] refactored config --- src/config.rs | 9 +++------ src/main.rs | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/config.rs b/src/config.rs index aece3da..555bbe4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -15,14 +15,12 @@ impl Config { compile_commands: false, } } - pub fn new(table: &Table) -> Self { - let mut ret = Self::get_default(); - + pub fn set(&mut self, table: &Table) { for k in table.keys() { match &*k.to_owned() { "build_dir" => { if let Value::String(s) = table.get(k).unwrap() { - ret.build_dir = s.to_owned(); + self.build_dir = s.to_owned(); } else { panic!("fatal: {k} invalid type, must be a string."); } @@ -30,7 +28,7 @@ impl Config { "compile_commands" => { if let Value::Boolean(b) = table.get(k).unwrap() { eprintln!("warn: config.compile_commands has no functionality (yet)"); - ret.compile_commands = *b; + self.compile_commands = *b; } else { panic!("fatal: {k} invalid type, must be a boolean."); } @@ -38,6 +36,5 @@ impl Config { _ => panic!("fatal: unrecognized key {k}."), } } - ret } } diff --git a/src/main.rs b/src/main.rs index 654566a..d5c7afe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -91,7 +91,7 @@ fn main() { for k in parsed_config.keys() { if let Value::Table(t) = parsed_config.get(k).unwrap() { if k == "config" { - config = Config::new(&t); + config.set(&t); } else { targets.push(Target::new(&t, k, Some(&targets[0]))); }