use std::path::Path; use std::io; use ini::Ini; pub struct Plymouthd { conf: Ini, } impl Plymouthd { pub fn from_ini(conf: Ini) -> Self { Self { conf } } pub fn from_file>(filename: P) -> io::Result { let conf = Ini::load_from_file(filename).map_err(|e| super::ini_to_io_err(e))?; Ok(Self { conf }) } pub fn default() -> io::Result { Self::from_file("/etc/plymouth/plymouthd.conf") } pub fn current_theme(&self) -> Option<&str> { self.conf .section(Some("Daemon")) .and_then(|s| s.get("Theme")) } } #[cfg(test)] mod tests { use super::*; #[test] fn default_theme_from_ini() { let mut ini = Ini::new(); ini.with_section(Some("Daemon")).set("Theme", "spinner"); let conf = Plymouthd::from_ini(ini); assert!(conf.current_theme().unwrap() == "spinner"); } }