[][src]Macro ini::ini

macro_rules! ini {
    {$($path: expr),+} => { ... };
    {safe $($path: expr),+} => { ... };
}

The ini! macro allows you to simply get a hashmap of type HashMap<String, HashMap<String, Option<String>>> for a list of files.

This example is not tested
#[macro_use]
extern crate ini;

fn main() {
  let map = ini!("...path/to/file");
  // Proceed to use normal HashMap functions on the map:
  let val = map["section"]["key"].clone().unwrap();
  // The type of the map is HashMap<String, HashMap<String, Option<String>>>

  // To load multiple files, just do:
  let (map1, map2, map3) = ini!("path/to/file1", "path/to/file2", "path/to/file3");
  // Each map is a cloned hashmap with no relation to other ones
}

If loading a file fails or the parser is unable to parse the file, the code will panic with an appropriate error. In case, you want to handle this gracefully, it's recommended you use the safe metavariable instead. This will make sure your code does not panic and instead exists as a Result<HashMap, String> type and let you deal with errors gracefully.

This example is not tested
let map = ini!(safe "...path/to/file");
 // Proceed to use normal HashMap functions on the map:
let val = map.unwrap()["section"]["key"].clone().unwrap();
 // Note the extra unwrap here, which is required because our HashMap is inside a Result type.