std_macro_extensions/b_tree_map/
macro.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/// A macro to create a new `BTreeMap`, providing two usage options:
///
/// 1. `b_tree_map!()` - Creates an empty `BTreeMap`.
/// 2. `b_tree_map!(key1 => value1, key2 => value2, ...)` - Creates a `BTreeMap` containing the specified key-value pairs.
///
/// # Examples:
///
/// ```rust
/// use std_macro_extensions::*;
/// let empty_map: BTreeMap<i32, i32> = b_tree_map!();
/// let populated_map = b_tree_map!(
///     "key1" => 1,
///     "key2" => 2,
///     "key3" => 3
/// );
/// ```
///
/// `BTreeMap` is an ordered map that allows iteration over keys in their sorted order. This macro simplifies the
/// process of creating `BTreeMap`, improving code readability and maintainability.
#[macro_export]
macro_rules! b_tree_map {
    () => {
        std::collections::BTreeMap::new()
    };
    ($($key:expr => $val:expr),*) => {{
        let mut map = std::collections::BTreeMap::new();
        $( map.insert($key, $val); )*
        map
    }};
}