i3status_rs

Macro map

source
macro_rules! map {
    (@extend $map:ident $( $([$($cond_tokens:tt)*])? $key:literal => $value:expr ),* $(,)?) => { ... };
    (@extend $map:ident $( $key:expr => $value:expr ),* $(,)?) => { ... };
    (@insert $map:ident, $key:expr, $value:expr) => { ... };
    (@insert $map:ident, $key:expr, $value:expr, if $cond:expr) => { ... };
    (@insert $map:ident, $key:expr, $value:expr, if let $pat:pat = $match_on:expr) => { ... };
    ($($tt:tt)*) => { ... };
}
Expand description

§Example

let opt = Some(1);
let m: HashMap<&'static str, String> = map! {
    "key" => "value",
    [if true] "hello" => "world",
    [if let Some(x) = opt] "opt" => x.to_string(),
};
map! { @extend m
    "new key" => "new value",
    "one" => "more",
}