From 1211a5f9a15ec78ff4d0925aa2d1f7e7824a125a Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 5 Sep 2020 19:16:10 +0100 Subject: [PATCH] Allow absence of [modules] in TOML file. Making the modules field of LogSpecification an Option allows it to be omitted entirely. This makes an empty log spec TOML valid. Signed-off-by: Ian Jackson --- src/log_specification.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/log_specification.rs b/src/log_specification.rs index 477e436..3ac2606 100644 --- a/src/log_specification.rs +++ b/src/log_specification.rs @@ -252,7 +252,7 @@ impl LogSpecification { struct LogSpecFileFormat { pub global_level: Option, pub global_pattern: Option, - pub modules: std::collections::BTreeMap, + pub modules: Option>, } let logspec_ff: LogSpecFileFormat = toml::from_str(s)?; @@ -266,7 +266,7 @@ impl LogSpecification { }); } - for (k, v) in logspec_ff.modules { + for (k, v) in logspec_ff.modules.unwrap_or_default() { module_filters.push(ModuleFilter { module_name: Some(k), level_filter: parse_level_filter(v)?, @@ -872,6 +872,11 @@ mod test_with_specfile { #[test] fn specfile() { + compare_specs( + "", + "", + ); + compare_specs( "[modules]\n\ ",