Expand description
Hierarchical INI parser and tree structure.
use hini::tree::build::{ToHiniString, TreeBuilder};
use hini::tree::Node;
use std::rc::Rc;
let config_contents = "
; This is an example file in hini format. comments start with # or ; and go
; to the end of the line. Files are UTF-8 Unicode text.
[ section ] ; Subsequent assignments become children of this node.
key name = a value ; Assignments give a key name and its value. Names and
; values are (valid UTF-8) strings.
[[ sub-section ]] # This section becomes a child of the top section node.
another-key = another value # These keys are children of the sub-section.
";
let tree_rc_ref = TreeBuilder::parse(config_contents, None).build_new().unwrap();
let mut config_root = Rc::into_inner(tree_rc_ref).unwrap().into_inner();
let section = config_root.get_child("section");
let value = section.borrow().get_child_value("key name");
assert_eq!(value, Some(String::from("a value")));
let subsection = section.borrow_mut().get_child("sub-section");
let value = subsection.borrow().get_child_value("another-key");
assert_eq!(value, Some(String::from("another value")));
let contents = ToHiniString {
indent: "",
section_separator: "",
start_comment: "",
..Default::default()
}.build(&config_root);
assert_eq!(contents, String::from("[section]
key name = a value
[[sub-section]]
another-key = another value
"));
Modules
- Parsers for reading data in hini format.
- The logical structure underpinning hini data.