From ee7fc4335a78661caa670e62cb9d5785c0169892 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 27 Nov 2018 12:54:40 +0100 Subject: [PATCH] SectionConfig::parse - return Value --- src/section_config.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/section_config.rs b/src/section_config.rs index 826117b8..d89415da 100644 --- a/src/section_config.rs +++ b/src/section_config.rs @@ -25,8 +25,8 @@ pub struct SectionConfig { plugins: HashMap, id_schema: Arc, - parse_section_header: fn(&str) -> Option<(String, String)>, - parse_section_content: fn(&str) -> Option<(String, String)>, + parse_section_header: fn(&str) -> Option<(String, String)>, + parse_section_content: fn(&str) -> Option<(String, String)>, } enum ParseState<'a> { @@ -49,7 +49,7 @@ impl SectionConfig { self.plugins.insert(plugin.type_name.clone(), plugin); } - pub fn parse(&self, filename: &str, raw: &str) -> Result<(), Error> { + pub fn parse(&self, filename: &str, raw: &str) -> Result { let mut line_no = 0; @@ -64,6 +64,15 @@ impl SectionConfig { Ok(()) }; + let mut result = json!({ + "ids": {}, + "order": {} + }); + + let mut create_section = |section_id, config| { + result[section_id] = config; + }; + for line in raw.lines() { line_no += 1; @@ -98,6 +107,7 @@ impl SectionConfig { if let Err(err) = test_required_properties(config, &plugin.properties) { bail!("file '{}' line {} - {}", filename, line_no, err.to_string()); } + create_section(section_id.clone(), config.clone()); state = ParseState::BeforeHeader; continue; } @@ -135,9 +145,10 @@ impl SectionConfig { if let Err(err) = test_required_properties(config, &plugin.properties) { bail!("file '{}' line {} - {}", filename, line_no, err.to_string()); } + create_section(section_id.clone(), config.clone()); } - Ok(()) + Ok(result) } pub fn default_parse_section_content(line: &str) -> Option<(String, String)> {