#[macro_export]
macro_rules! hashmap {
    {$($key:expr => $value:expr),*} => {{
        let mut map = ::std::collections::HashMap::new();
        $( map.insert($key, $value); )*
        map
    }};

    // hashmap!{"key" => "value", "key2" => "value3",}
    {$($k:expr => $v:expr),+ $(,)?} => (
        hashmap! ($($k => $v),*)
    );

    // 单个方法回调处理参数:
    //      let map = hashmap!{|v: &str|v.to_owned();
    //         "1111" => "22222",
    //         "3333" => "4444",
    //         "555" => "6666",
    //     };
    {$fun:expr; $($key:expr => $value:expr),+ $(,)?} => {{
        let mut map = ::std::collections::HashMap::new();
        $( map.insert($fun($key), $fun($value)); )*
        map
    }};

    // 键和值, 双方法处理参数:
    //      let map = hashmap!{|v: &str|v.to_owned(); |v: &str| format!("add params + {}", v);
    //         "1111" => "22222",
    //         "3333" => "4444",
    //     };
    {$fun1:expr; $fun2:expr; $($key:expr => $value:expr),+ $(,)?} => {{
        let mut map = ::std::collections::HashMap::new();
        $( map.insert($fun1($key), $fun2($value)); )*
        map
    }};
}



#[test]
fn test() {
    // let map = hashmap!(
    //     "guoyu1" => "111",
    //     "guoyu2" => "2222",
    // );
    let map = hashmap! {|v: &str|v.to_owned(); |v: &str| format!("add params + {}", v);
        "1111" => "22222",
        "3333" => "4444",
        "555" => "6666",
    };
    println!("{:?}", map);

    let map = hashmap! {
        "7777" => "8888",
        "9999" => "1010101",
    };
    println!("{:?}", map);
}

#[cfg(debug_assertions)]
#[macro_export]
macro_rules! dev_or_prod {
    ($dev_v:expr, $prod_v:expr) => {
        $dev_v
    };
}
#[cfg(not(debug_assertions))]
#[macro_export]
macro_rules! dev_or_prod {
    ($dev_v:expr, $prod_v:expr) => {
        $prod_v
    };
}

#[test]
fn test_dev_or_prod(){
    println!("{}", dev_or_prod!("123", "456"))
}


#[macro_export]
macro_rules! ddebug {
    // debug!(target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
    // debug!(target: "my_target", "a {} event", "log")
    (target: $target:expr, $($arg:tt)+) => (
        #[cfg(debug_assertions)]
        log!(target: $target, log::Level::Debug, $($arg)+)
    );

    // debug!("a {} event", "log")
    ($($arg:tt)+) => (
        #[cfg(debug_assertions)]
        log!(log::Level::Debug, $($arg)+)
    )
}

#[test]
fn test_ddbug(){
    ddebug!("dgdfgdfgdf");
    ddebug!("{}", 123123);
}