Function nccl::parse_config_with[][src]

pub fn parse_config_with<'a>(
    config: &Config<'a>,
    content: &'a str
) -> Result<Config<'a>, NcclError>
Expand description

Parse a new nccl configuration on top of another

e.g.

// user.nccl:
// beans
//    four

// default.nccl:
// frog
//     yes
// beans
//     none

// result:
// frog
//     yes
// beans
//     four
//     none

// first get the user config
let user = std::fs::read_to_string("examples/user.nccl").unwrap();
let user_config = parse_config(&user).unwrap();

// then merge the default config on top of the user config
let default = std::fs::read_to_string("examples/default.nccl").unwrap();
let combined_config = parse_config_with(&user_config, &default).unwrap();

// with value(), the first key inserted is returned. since we read the user
// config first, the user-supplied value is first, overriding the default.
assert_eq!(combined_config["beans"].value(), Some("four"));
// "beans" now has two values
assert_eq!(combined_config["beans"].values().count(), 2);

// and the unmodified key remains
assert_eq!(combined_config["frog"].value(), Some("yes"));