/////////// main.rs ////////////////////
use std::collections::{HashMap,HashSet};
// from https://github.com/rust-lang/rust/issues/14726
macro_rules! seq {
($($x:expr),+) => {
[$($x,)+].iter().map(|&x| x).collect()
}
}
fn main() {
let set: HashSet
let map1: HashMap
let map2: HashMap<&'static str, &'static str> =
seq!(("A", "1"),
("B", "2"),
("C", "3"));
// demonstrate without macro
let map3: HashMap<&'static str, &'static str> =
[ ("A", "1"),
("B", "2"),
("C", "3") ]
.iter().map(|&x| x).collect();
println!("Set: {:?}", set);
println!("Map: {:?}", map1);
println!("Map: {:?}", map2);
println!("Map: {:?}", map3);
}
No comments:
Post a Comment