use pom_parser::Configuration; use std::process::ExitCode; fn try_main() -> Result<(), Box> { // Try editing examples/conf.pom and see how the output changes! let conf = Configuration::load_path("examples/conf.pom")?; // get looks up a key in a configuration file. // it returns Some(value) if the key is set to value, // and None otherwise. println!( "indenting with {}", conf.get("indentation-type") .ok_or("you must pick an indentation-type!")? ); // get_int_or_default parses a key as an integer. // It returns an Err if the key is set to something that’s not a valid integer. println!("tab width is {}", conf.get_int_or_default("tab-size", 8)?); // get_bool_or_default parses a key as a boolean. // no, off, false all count as false, and yes, on, true count as true. println!( "show line numbers: {}", conf.get_bool_or_default("show-line-numbers", false)? ); // lists are comma-separated. they can use \, to escape literal commas. println!("C++ extensions: {:?}", conf.get_list("file-extensions.Cpp")); println!("===plug-ins==="); // extract out a section of a configuration let plug_ins = conf.section("plug-in"); for plug_in in plug_ins.keys() { // extract out just this plug-in's section let plug_in_cfg = plug_ins.section(plug_in); println!( "{plug_in} is {}", if plug_in_cfg.get_bool_or_default("enabled", true)? { "enabled" } else { "disabled" } ); println!( "{plug_in} plug-in path: {:?}", plug_in_cfg .get("path") .ok_or_else(|| format!("no path set for plug-in {plug_in}!"))? ); } Ok(()) } fn main() -> ExitCode { if let Err(e) = try_main() { eprintln!("Error: {e}"); return ExitCode::FAILURE; } ExitCode::SUCCESS }