12
12
/// "de" => "Auf Wiedersehen",
13
13
/// "fr" => "Au revoir",
14
14
/// "es" => "Adios",
15
+ /// "cat" => "Adéu",
15
16
/// };
16
17
/// ```
17
18
///
@@ -22,8 +23,9 @@ macro_rules! hash_map {
22
23
} ;
23
24
}
24
25
25
- /// Explicitly typed equivalent of [`hash_map!`], suitable for
26
- /// [trait object values](crate#explicitly-typed-values-for-trait-objects).
26
+ /// Explicitly typed equivalent of [`hash_map!`].
27
+ ///
28
+ /// See the [explicity typed macros](crate#explicitly-typed-macros) section.
27
29
///
28
30
/// # Examples
29
31
///
@@ -38,6 +40,7 @@ macro_rules! hash_map {
38
40
/// "de" => &"Auf Wiedersehen",
39
41
/// "fr" => &"Au revoir",
40
42
/// "es" => &"Adios",
43
+ /// "cat" => &"Adéu",
41
44
/// };
42
45
///
43
46
/// println!("{:?}", goodbye);
@@ -64,6 +67,7 @@ macro_rules! hash_map_e {
64
67
/// "de" => "Auf Wiedersehen",
65
68
/// "fr" => "Au revoir",
66
69
/// "es" => "Adios",
70
+ /// "cat" => "Adéu",
67
71
/// };
68
72
/// ```
69
73
///
@@ -74,8 +78,9 @@ macro_rules! btree_map {
74
78
} ;
75
79
}
76
80
77
- /// Explicitly typed equivalent of [`btree_map!`], suitable for
78
- /// [trait object values](crate#explicitly-typed-values-for-trait-objects).
81
+ /// Explicitly typed equivalent of [`btree_map!`].
82
+ ///
83
+ /// See the [explicity typed macros](crate#explicitly-typed-macros) section.
79
84
///
80
85
/// # Examples
81
86
///
@@ -90,6 +95,7 @@ macro_rules! btree_map {
90
95
/// "de" => &"Auf Wiedersehen",
91
96
/// "fr" => &"Au revoir",
92
97
/// "es" => &"Adios",
98
+ /// "cat" => &"Adéu",
93
99
/// };
94
100
/// ```
95
101
///
@@ -121,6 +127,31 @@ macro_rules! hash_set {
121
127
} ;
122
128
}
123
129
130
+ /// Explicitly typed equivalent of [`hash_set!`].
131
+ ///
132
+ /// See the [explicity typed macros](crate#explicitly-typed-macros) section.
133
+ ///
134
+ /// # Examples
135
+ ///
136
+ /// ```rust
137
+ /// use std::collections::HashSet;
138
+ ///
139
+ /// use map_macro::hash_set_e;
140
+ ///
141
+ /// enum Foo { A, B, C, D }
142
+ ///
143
+ /// let x: HashSet<u8> = hash_set_e! { Foo::A, Foo::B, Foo::C, Foo::C, Foo::D };
144
+ ///
145
+ /// assert_eq!(x.len(), 4);
146
+ /// ```
147
+ ///
148
+ #[ macro_export]
149
+ macro_rules! hash_set_e {
150
+ { $( $v: expr) ,* $( , ) ?} => {
151
+ :: std:: collections:: HashSet :: from( [ $( $v as _, ) * ] )
152
+ } ;
153
+ }
154
+
124
155
/// Macro for creating a [`BTreeSet`](::std::collections::BTreeSet).
125
156
///
126
157
/// Syntactic sugar for [`BTreeSet::from`](::std::collections::BTreeSet::from).
@@ -142,6 +173,31 @@ macro_rules! btree_set {
142
173
} ;
143
174
}
144
175
176
+ /// Explicitly typed equivalent of [`btree_set!`].
177
+ ///
178
+ /// See the [explicity typed macros](crate#explicitly-typed-macros) section.
179
+ ///
180
+ /// # Examples
181
+ ///
182
+ /// ```rust
183
+ /// use std::collections::BTreeSet;
184
+ ///
185
+ /// use map_macro::btree_set_e;
186
+ ///
187
+ /// enum Foo { A, B, C, D }
188
+ ///
189
+ /// let x: BTreeSet<u8> = btree_set_e! { Foo::A, Foo::B, Foo::C, Foo::C, Foo::D };
190
+ ///
191
+ /// assert_eq!(x.len(), 4);
192
+ /// ```
193
+ ///
194
+ #[ macro_export]
195
+ macro_rules! btree_set_e {
196
+ { $( $v: expr) ,* $( , ) ?} => {
197
+ :: std:: collections:: BTreeSet :: from( [ $( $v as _, ) * ] )
198
+ } ;
199
+ }
200
+
145
201
/// Macro for creating a [`VecDeque`](::std::collections::VecDeque).
146
202
///
147
203
/// Follows the same syntax as the [`vec!`](::std::vec!) macro.
@@ -173,8 +229,9 @@ macro_rules! vec_deque {
173
229
} ;
174
230
}
175
231
176
- /// Explicitly typed equivalent of [`vec_deque!`], suitable for
177
- /// [trait object values](crate#explicitly-typed-values-for-trait-objects).
232
+ /// Explicitly typed equivalent of [`vec_deque!`].
233
+ ///
234
+ /// See the [explicity typed macros](crate#explicitly-typed-macros) section.
178
235
///
179
236
/// # Examples
180
237
///
@@ -237,8 +294,9 @@ macro_rules! linked_list {
237
294
} ;
238
295
}
239
296
240
- /// Explicitly typed equivalent of [`linked_list!`], suitable for
241
- /// [trait object values](crate#explicitly-typed-values-for-trait-objects).
297
+ /// Explicitly typed equivalent of [`linked_list!`].
298
+ ///
299
+ /// See the [explicity typed macros](crate#explicitly-typed-macros) section.
242
300
///
243
301
/// # Examples
244
302
///
@@ -301,6 +359,41 @@ macro_rules! binary_heap {
301
359
} ;
302
360
}
303
361
362
+ /// Explicitly typed equivalent of [`binary_heap!`].
363
+ ///
364
+ /// See the [explicity typed macros](crate#explicitly-typed-macros) section.
365
+ ///
366
+ /// # Examples
367
+ ///
368
+ /// ```
369
+ /// use std::collections::BinaryHeap;
370
+ ///
371
+ /// use map_macro::binary_heap_e;
372
+ ///
373
+ /// enum Foo { A, B, C, D }
374
+ ///
375
+ /// let v: BinaryHeap<u8> = binary_heap_e![Foo::A, Foo::B, Foo::C, Foo::D];
376
+ /// let v: BinaryHeap<u8> = binary_heap_e![Foo::A; 4];
377
+ /// ```
378
+ ///
379
+ #[ macro_export]
380
+ macro_rules! binary_heap_e {
381
+ { $v: expr; $c: expr} => {
382
+ {
383
+ let mut bh = :: std:: collections:: BinaryHeap :: with_capacity( $c) ;
384
+
385
+ for _ in 0 ..$c {
386
+ bh. push( $v as _) ;
387
+ }
388
+
389
+ bh
390
+ }
391
+ } ;
392
+ { $( $v: expr) ,* $( , ) ?} => {
393
+ :: std:: collections:: BinaryHeap :: from( [ $( $v as _, ) * ] )
394
+ } ;
395
+ }
396
+
304
397
/// Version of the [`vec!`](::std::vec!) macro where the value does not have to implement [`Clone`].
305
398
///
306
399
/// Useful for unclonable types or where `Clone` is exerting undesired behaviour.
@@ -439,6 +532,7 @@ macro_rules! binary_heap {
439
532
#[ macro_export]
440
533
macro_rules! vec_no_clone {
441
534
{ $v: expr; $c: expr} => {
535
+
442
536
{
443
537
let mut vec = Vec :: with_capacity( $c) ;
444
538
@@ -455,3 +549,38 @@ macro_rules! vec_no_clone {
455
549
}
456
550
} ;
457
551
}
552
+
553
+ /// Explicitly typed equivalent of [`vec_no_clone!`].
554
+ ///
555
+ /// See the [explicity typed macros](crate#explicitly-typed-macros) section.
556
+ ///
557
+ /// # Examples
558
+ ///
559
+ /// ```
560
+ /// use std::fmt::Display;
561
+ ///
562
+ /// use map_macro::vec_no_clone_e;
563
+ ///
564
+ /// let v: Vec<&dyn Display> = vec_no_clone_e![&0; 4];
565
+ /// ```
566
+ ///
567
+ #[ macro_export]
568
+ macro_rules! vec_no_clone_e {
569
+ { $v: expr; $c: expr} => {
570
+
571
+ {
572
+ let mut vec = Vec :: with_capacity( $c) ;
573
+
574
+ for _ in 0 ..$c {
575
+ vec. push( $v as _) ;
576
+ }
577
+
578
+ vec
579
+ }
580
+ } ;
581
+ { $( $v: expr) ,* $( , ) ?} => {
582
+ {
583
+ vec![ $( $v as _) ,* ]
584
+ }
585
+ } ;
586
+ }
0 commit comments