5 releases
| 0.1.5 | Jan 1, 2026 |
|---|---|
| 0.1.4 | Dec 29, 2025 |
| 0.1.3 | May 30, 2025 |
| 0.1.2 | May 30, 2025 |
| 0.1.0 | May 25, 2025 |
#1661 in Rust patterns
73 downloads per month
Used in 5 crates
(via macron)
7KB
69 lines
Std::Collections Declarative Macros
Introduction:
Creates a new instance of std collections: HashMap, HashSet, BTreeMap, BTreeSet, VecDeque, LinkedList and BinaryHeap.
P.s.: More useful macros you can find here.
Examples:
VecDeque
let mut deque = vec_deque![1, 2, 3];
assert_eq!(deque.len(), 3);
assert_eq!(deque.pop_front(), Some(1));
assert_eq!(deque.pop_back(), Some(3));
HashMap
let key = "one";
let val = 1;
let map = hash_map! {
key => val,
"two": 2,
"three" => 3,
"four": 4
};
assert_eq!(map.get("one"), Some(&1));
assert_eq!(map.get("two"), Some(&2));
HashSet
let set = hash_set![1, 2, 3];
assert!(set.contains(&1));
assert!(set.contains(&2));
BTreeMap
let key = "one";
let val = 1;
let map = btree_map! {
key => val,
"two": 2,
"three" => 3,
"four": 4
};
assert_eq!(map.get("one"), Some(&1));
assert_eq!(map.get("two"), Some(&2));
BTreeSet
let set = btree_set![4, 5, 6];
assert!(set.contains(&4));
assert!(set.contains(&5));
BinaryHeap
let mut heap = binary_heap![3, 1, 2];
assert_eq!(heap.pop(), Some(3));
assert_eq!(heap.pop(), Some(2));
assert_eq!(heap.pop(), Some(1));
LinkedList
let mut list = linked_list![10, 20, 30];
assert_eq!(list.len(), 3);
assert_eq!(list.pop_front(), Some(10));
assert_eq!(list.pop_back(), Some(30));
Licensing:
Distributed under the MIT license.
Feedback:
You can contact me via GitHub or send a message to my Telegram @fuderis.
This library is constantly evolving, and I welcome your suggestions and feedback.
Dependencies
~135–530KB
~13K SLoC