macro_rules! sectioned_defaults {
(
{
$($general_key:expr => $general_value:expr),* $(,)?
}
$(
[$section:expr] {
$($key:expr => $value:expr),* $(,)?
}
)*) => { ... };
($(
[$section:expr] {
$($key:expr => $value:expr),* $(,)?
}
)*) => { ... };
}Expand description
Generate a Config object with sections and default values.
Variables are supported in section, key, and value fields, but must be strings.
ยงSyntax
let server_section = "Server"; // Variables are supported
let default_host = "127.0.0.1"; // across all fields.
let secure = "true"; // Value must be a string!
let mut config: Config = sectioned_defaults! {
// Optional general section (no section title)
// must be the first section if included
{
"console" => "true",
}
// Section titles are enclosed in square brackets
[server_section] {
"host" => default_host,
"port" => "8080",
}
["Window"] {
"width" => "720",
"height" => "480",
}
};