hashmap_ex

Macro hashmap_ex 

Source
macro_rules! hashmap_ex {
    (@single $($x:tt)*) => { ... };
    (@count $($rest:expr),*) => { ... };
    ($t:ty, { $($key:expr => $value:expr,)+ } ) => { ... };
    ($t:ty, { $($key:expr => $value:expr),* } ) => { ... };
}
Expand description

Create a HashMap with specific type from a list of key-value pairs

§Example

#[macro_use] extern crate maplit;
use std::collections::HashMap;
struct Foo;
struct Bar;

trait Zoo {}

impl Zoo for Foo {}
impl Zoo for Bar {}

let map = hashmap_ex!(
    HashMap<_, Box<dyn Zoo>>,
    {
        "a" => Box::new(Foo {}),
        "b" => Box::new(Bar {}),
    }
);