其他分享
首页 > 其他分享> > rust 宏

rust 宏

作者:互联网

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);
}

  

标签:map,HashMap,val,123,let,hm,rust
来源: https://www.cnblogs.com/pythonClub/p/16483117.html