From: Ian Jackson Date: Sat, 7 Aug 2021 20:03:44 +0000 (+0100) Subject: ini: new module compiles X-Git-Tag: hippotat/1.0.0~259 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=4fea9e4590385834ffc0b13360dc7b87ec52c978;p=hippotat.git ini: new module compiles Signed-off-by: Ian Jackson --- diff --git a/src/ini.rs b/src/ini.rs index 107f4aa..0d60b79 100644 --- a/src/ini.rs +++ b/src/ini.rs @@ -4,7 +4,9 @@ use crate::prelude::*; +use std::cell::{RefCell, RefMut}; use std::io::BufRead; +use std::rc::Rc; #[derive(Debug,Clone)] #[derive(Hash,Eq,PartialEq,Ord,PartialOrd)] @@ -47,10 +49,14 @@ impl Display for Loc { } } + #[throws(AE)] -pub fn read(parsed: &mut Parsed, file: &mut dyn BufRead, path_for_loc: &Path) { +pub fn read(parsed: &mut Parsed, file: &mut dyn BufRead, path_for_loc: &Path) +//->Result<(), AE> +{ + let parsed = Rc::new(RefCell::new(parsed)); let path: Arc = path_for_loc.to_owned().into(); - let mut section: Option<&mut Section> = None; + let mut section: Option> = None; for (lno, line) in file.lines().enumerate() { let line = line.context("read")?; let line = line.trim(); @@ -69,15 +75,22 @@ pub fn read(parsed: &mut Parsed, file: &mut dyn BufRead, path_for_loc: &Path) { regex_captures!(r#"^ \[ \s* (.+?) \s* \] $"#x, line) { let new: Arc = new.to_owned().into(); - section = Some( - parsed.entry(new.clone()) + + section.take(); // drops previous RefCell borrow of parsed + + let new_section = RefMut::map(parsed.borrow_mut(), |p| { + + p.entry(new.clone()) .or_insert_with(|| { Section { loc: Loc { section: Some(new), file: path.clone(), lno }, values: default(), - } + } }) - ); + + }); + + section = Some(new_section); } else if let Some((_, key, val)) = regex_captures!(r#"^ ( [^\[] .*? ) \s* = \s* (.*) $"#, line) diff --git a/src/lib.rs b/src/lib.rs index 1327974..298c1b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,4 +13,4 @@ pub mod queue; pub mod types; pub mod utils; -//mod ini; +pub mod ini;