brawl_api/macros.rs
1#![doc(hidden)]
2/// Concats string(s) to the main API URI.
3///
4/// # Examples
5///
6/// ```rust
7/// use brawl_api::b_api_concat;
8///
9/// assert_eq!(
10/// b_api_concat!("players/"),
11/// "https://api.brawlstars.com/v1/players/"
12/// )
13/// ```
14#[macro_export]
15macro_rules! b_api_concat {
16 ($($s:expr),*) => {
17 concat!("https://api.brawlstars.com/v1/", $($s,)*)
18 }
19}
20
21/// Constructs any Map<Key, Value> type, based on an initializer expression.
22///
23/// # Examples
24/// ```rust,ignore
25/// let custom_map = map_build!{
26/// MyMap::new();
27/// "key" => "val",
28/// "other_key" => value,
29/// key => "val",
30/// }
31///
32/// // Expands to
33///
34/// let custom_map = MyMap::new();
35/// custom_map.insert("key", "val");
36/// custom_map.insert("other_key", value);
37/// custom_map.insert(key, "val");
38/// ```
39#[macro_export]
40macro_rules! map_build {
41 ($initializer:expr; $($key:expr => $val:expr),*) => {
42 {
43 let m = $initializer;
44 $(
45 m.insert($key, $val);
46 )*
47 m
48 }
49 }
50}
51
52