Crate cni_format[−][src]
Expand description
This is a parser library for the CNI configuration format (CoNfiguration Initialization format) by libuconf.
CNI standard compliance
The implementation is fully compliant with the core
and
ini
part of the specification and with the extension more-keys
.
Examples
use std::collections::HashMap; let cni = r" [section] key = value rkey = `raw value with `` escaped` subsection.key = look, whitespace! "; let parsed = cni_format::from_str(&cni).expect("could not parse CNI"); // You can get everything, section names will be prepended to key names. { let mut result: HashMap<String, String> = HashMap::new(); result.insert("section.key".to_string(), "value".to_string()); result.insert("section.rkey".to_string(), "raw value with ` escaped".to_string()); result.insert("section.subsection.key".to_string(), "look, whitespace!".to_string()); assert_eq!(parsed, result); } // You can get values from one section only. { let mut section: HashMap<String, String> = HashMap::new(); section.insert("key".to_string(), "value".to_string()); section.insert("rkey".to_string(), "raw value with ` escaped".to_string()); section.insert("subsection.key".to_string(), "look, whitespace!".to_string()); // use trait that adds CNI related functionality use cni_format::CniExt; // filter out values in section "section" assert_eq!(parsed.sub_tree("section"), section); } // You can get child nodes from one section only, excluding subsections. { let mut section: HashMap<String, String> = HashMap::new(); section.insert("key".to_string(), "value".to_string()); section.insert("rkey".to_string(), "raw value with ` escaped".to_string()); // use trait that adds CNI related functionality use cni_format::CniExt; // filter out values in section "section", but not in subsections assert_eq!(parsed.sub_leaves("section"), section); }
Structs
An iterator that visits all key/value pairs in declaration order, even key/value pairs that will be overwritten by later statements.
A struct to pass parsing options. Contains the switches to enable the different extensions.
An iterator that filters the elements of a key-value iterator for keys in a specific section.
Traits
Provides the recommended API functions:
Functions
Parses CNI format text and returns the resulting key/value store. The parsing options are set to the default values.
Parses CNI format text and returns the resulting key/value store, using the specified options.
Turn a key/value store into CNI format text. Accepts a wide range of keys, values and map types. The output will contain as few section headers as possible, but if a key consists of multiple parts separated by a dot, the first one will always be used for the section name