macro_rules! vecmap {
(@single $($x:tt)*) => { ... };
(@count $($rest:expr),*) => { ... };
( strict, data = { $( $key:expr => $value:expr, )+ } $( , )? ) => { ... };
( strict, data = { $( $key:expr => $value:expr ),* } $( , )? ) => { ... };
( $( $key:expr => $value:expr, )+ ) => { ... };
( $( $key:expr => $value:expr ),* ) => { ... };
() => { ... };
}Expand description
Create a VecMap from a list of key-value pairs.
While based off of maplit, this is an
extended version with the ability to enable a strict mode.
§Examples
let map = fenn::vecmap! {
"a" => 1,
"b" => 2,
};
assert_eq!(map["a"], 1);
assert_eq!(map["b"], 2);
assert_eq!(map.get("c"), None);When strict mode is active, a duplicate key will cause a panic.
ⓘ
let map = fenn::vecmap! {
strict,
data = {
"a" => 1,
"a" => 2, // panics
}
};