use std::collections::HashMap; macro_rules! map { ($($key:expr => $val:expr),*) => {{ let mut hm = HashMap::new(); $(hm.insert($key, $val);)* hm }}; //要返回,相当于是FN,所以必须多加一对{} } fn main(){ let a = map!("s" => 123, "xx"=>34, "uu"=>123); println!("{:?}", a); }