From 052b950ca0ddb7e5261c7d7bc105a638b5cede1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Autin?= Date: Fri, 21 Apr 2023 14:39:49 +0200 Subject: [PATCH] :memo: Updated cfg.rs documentation --- src/utility/cfg.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/utility/cfg.rs b/src/utility/cfg.rs index f12e51f..69ba6d1 100644 --- a/src/utility/cfg.rs +++ b/src/utility/cfg.rs @@ -93,7 +93,6 @@ pub fn read_settings() -> Result { } /// Returns a mock configuration for Machine unit testing -/// FIXME: Does not cover the whole configuration yet pub fn get_debug_configuration() -> Settings { let mut settings_map = Settings::new(); settings_map.insert(MachineSettingKey::PageSize, 128); @@ -101,16 +100,23 @@ pub fn get_debug_configuration() -> Settings { settings_map } +/// Filters out empty lines and comments from the reader `BufReader`. +/// +/// Returns a [`Vec`], each entry containing a valid +/// line from the input file. fn filter_garbage(reader: BufReader) -> Vec { reader.lines() .map(|l| l.unwrap()) - .filter(|l| !l.is_empty() && !l.starts_with("#")) + .filter(|l| !l.is_empty() && !l.starts_with('#')) .collect() } +/// Adds a pair to a [`Settings`] map. +/// +/// Returns the updated [`Settings`]. fn update_settings_map(mut settings_map: Settings, key: &str, setting: &str) -> Settings { let key = MachineSettingKey::from(key); - let setting = u64::from_str_radix(setting, 10).unwrap_or(0); + let setting = str::parse::(setting).unwrap_or(0); settings_map.insert(key, setting); settings_map } \ No newline at end of file