📝 Updated cfg.rs documentation

This commit is contained in:
François Autin 2023-04-21 14:39:49 +02:00
parent f06f14354a
commit 052b950ca0
No known key found for this signature in database
GPG Key ID: 343F5D382E1DD77C

View File

@ -93,7 +93,6 @@ pub fn read_settings() -> Result<Settings, Error> {
} }
/// Returns a mock configuration for Machine unit testing /// Returns a mock configuration for Machine unit testing
/// FIXME: Does not cover the whole configuration yet
pub fn get_debug_configuration() -> Settings { pub fn get_debug_configuration() -> Settings {
let mut settings_map = Settings::new(); let mut settings_map = Settings::new();
settings_map.insert(MachineSettingKey::PageSize, 128); settings_map.insert(MachineSettingKey::PageSize, 128);
@ -101,16 +100,23 @@ pub fn get_debug_configuration() -> Settings {
settings_map settings_map
} }
/// Filters out empty lines and comments from the reader `BufReader`.
///
/// Returns a [`Vec<String>`], each entry containing a valid
/// line from the input file.
fn filter_garbage<R: std::io::Read>(reader: BufReader<R>) -> Vec<String> { fn filter_garbage<R: std::io::Read>(reader: BufReader<R>) -> Vec<String> {
reader.lines() reader.lines()
.map(|l| l.unwrap()) .map(|l| l.unwrap())
.filter(|l| !l.is_empty() && !l.starts_with("#")) .filter(|l| !l.is_empty() && !l.starts_with('#'))
.collect() .collect()
} }
/// Adds a <K, V> pair to a [`Settings`] map.
///
/// Returns the updated [`Settings`].
fn update_settings_map(mut settings_map: Settings, key: &str, setting: &str) -> Settings { fn update_settings_map(mut settings_map: Settings, key: &str, setting: &str) -> Settings {
let key = MachineSettingKey::from(key); let key = MachineSettingKey::from(key);
let setting = u64::from_str_radix(setting, 10).unwrap_or(0); let setting = str::parse::<u64>(setting).unwrap_or(0);
settings_map.insert(key, setting); settings_map.insert(key, setting);
settings_map settings_map
} }