Created
February 20, 2017 23:30
-
-
Save matematikaadit/803bfb2a993b9b4cbb13bd69e8c4bb8a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// License | |
// | |
// Dual-licensed to be compatible with the Rust project. | |
// | |
// Licensed under the Apache License, Version 2.0 | |
// http://www.apache.org/licenses/LICENSE-2.0 or the MIT license | |
// http://opensource.org/licenses/MIT, at your option. This file may not | |
// be copied, modified, or distributed except according to those terms. | |
// | |
// From: https://github.com/bluss/maplit | |
macro_rules! hashmap { | |
(@single $($x:tt)*) => (()); | |
(@count $($rest:expr),*) => (<[()]>::len(&[$(hashmap!(@single $rest)),*])); | |
($($key:expr => $value:expr,)+) => { hashmap!($($key => $value),+) }; | |
($($key:expr => $value:expr),*) => { | |
{ | |
let _cap = hashmap!(@count $($key),*); | |
let mut _map = ::std::collections::HashMap::with_capacity(_cap); | |
$( | |
_map.insert($key, $value); | |
)* | |
_map | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment