Improve map! macro to allow extending the map with other map

This commit is contained in:
Tobie Morgan Hitchcock 2022-07-04 02:01:22 +01:00
parent 983a7b3f5c
commit 410295c800

View file

@ -1,6 +1,7 @@
macro_rules! map { macro_rules! map {
($($k:expr => $v:expr),* $(,)?) => {{ ($($k:expr => $v:expr),* $(,)? $( => $x:expr )?) => {{
let mut m = ::std::collections::BTreeMap::new(); let mut m = ::std::collections::BTreeMap::new();
$(m.extend($x.iter().map(|(k, v)| (k.clone(), v.clone())));)?
$(m.insert($k, $v);)+ $(m.insert($k, $v);)+
m m
}}; }};