use std::fmt; use crate::{fs::WikPath, table::TableData}; #[derive(Clone, Debug)] pub struct SectionData { home: Option, } impl SectionData { pub fn home(&self) -> Option<&WikPath> { self.home.as_ref() } pub fn set_home>(&mut self, home: Option

) { self.home = home.map(|h| h.into()); } } impl Default for SectionData { fn default() -> Self { Self { home: None } } } impl TableData for SectionData { fn parse(raw: &str) -> Result { // WARNING: the split here is unsafe, as it will split comma in the // quoted strings as well. we need to handle this, probably with a // new iterator. it is okay for now, but be warned. let mut splits = raw.split(',').filter_map(|s| s.split_once('=')); let mut home = None; while let Some((key, value)) = splits.next() { let decoded = match crate::quotes_decode(value) { None => continue, Some((value, _rest)) => value, }; match key { "home" => home = Some(decoded.into()), _ => (), } } Ok(Self { home }) } } impl fmt::Display for SectionData { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if let Some(home) = self.home.as_ref() { let quoted_home = crate::quotes_encode(home.as_ref()); write!(f, "home={quoted_home}")?; } Ok(()) } }