Struct nccl::config::Config [−][src]
pub struct Config<'a> { /* fields omitted */ }
Expand description
A nccl configuration
Indexable with &str
.
e.g.
// config.nccl:
// server
// domain
// example.com
// www.example.com
// port
// 80
// 443
// root
// /var/www/html
let content = std::fs::read_to_string("examples/config.nccl").unwrap();
let config = parse_config(&content).unwrap();
// get the value of a single node
assert_eq!(Some("/var/www/html"), config["server"]["root"].value());
// value always returns the value of the first child node
assert_eq!(Some("example.com"), config["server"]["domain"].value());
// get multiple values
assert_eq!(
vec!["example.com", "www.example.com"],
config["server"]["domain"].values().collect::<Vec<_>>()
);
// parse multiple values
assert_eq!(
Ok(vec![80, 443]),
config["server"]["port"]
.values()
.map(|value| value.parse::<u16>())
.collect::<Result<Vec<_>, _>>()
);
Implementations
Iterator for the children of a node.
The first child of the node.
// excerpt of long.nccl:
// strings
// in which case
// "just\nuse quotes"
let source = std::fs::read_to_string("examples/long.nccl").unwrap();
let config = parse_config(&source).unwrap();
assert_eq!(
"just\nuse quotes",
config["strings"]["in which case:"]
.child()
.unwrap()
.parse_quoted()
.unwrap()
);
Parse the string including escape sequences if it’s quoted.
See Config::child
.
Trait Implementations
Auto Trait Implementations
impl<'a> RefUnwindSafe for Config<'a>
impl<'a> UnwindSafe for Config<'a>
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.