1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
//! Rust macro for fast HashMap initialisation. //! //! # Examples //! //! ```rust //! #[macro_use] //! extern crate hashmacro; //! use std::collections::HashMap; //! //! fn main () { //! let hashmap: HashMap<_, u32> = hashmap! { //! foo: 2u32, //! bar: 33u32 //! }; //! } //! ``` #[macro_export] macro_rules! hashmap { ( $($key:ident : $value:expr),* ) => {{ let mut hash = HashMap::<&str, _>::new(); $( hash.insert(stringify!($key), $value); )* hash }}; }