1
+ pub ( crate ) use self :: macros:: * ;
1
2
use crate :: { formats:: * , prelude:: * } ;
2
3
#[ cfg( feature = "hashbrown_0_14" ) ]
3
4
use hashbrown_0_14:: { HashMap as HashbrownMap014 , HashSet as HashbrownSet014 } ;
@@ -12,89 +13,98 @@ use indexmap_2::{IndexMap as IndexMap2, IndexSet as IndexSet2};
12
13
#[ cfg( feature = "alloc" ) ]
13
14
type BoxedSlice < T > = Box < [ T ] > ;
14
15
15
- macro_rules! foreach_map {
16
- ( $m: ident) => {
17
- #[ cfg( feature = "alloc" ) ]
18
- $m!( BTreeMap <K : Ord , V >, ( |_size| BTreeMap :: new( ) ) ) ;
19
- #[ cfg( feature = "std" ) ]
20
- $m!(
21
- HashMap <K : Eq + Hash , V , S : BuildHasher + Default >,
22
- ( |size| HashMap :: with_capacity_and_hasher( size, Default :: default ( ) ) )
23
- ) ;
24
- #[ cfg( feature = "hashbrown_0_14" ) ]
25
- $m!(
26
- HashbrownMap014 <K : Eq + Hash , V , S : BuildHasher + Default >,
27
- ( |size| HashbrownMap014 :: with_capacity_and_hasher( size, Default :: default ( ) ) )
28
- ) ;
29
- #[ cfg( feature = "indexmap_1" ) ]
30
- $m!(
31
- IndexMap <K : Eq + Hash , V , S : BuildHasher + Default >,
32
- ( |size| IndexMap :: with_capacity_and_hasher( size, Default :: default ( ) ) )
33
- ) ;
34
- #[ cfg( feature = "indexmap_2" ) ]
35
- $m!(
36
- IndexMap2 <K : Eq + Hash , V , S : BuildHasher + Default >,
37
- ( |size| IndexMap2 :: with_capacity_and_hasher( size, Default :: default ( ) ) )
38
- ) ;
39
- } ;
40
- }
41
- pub ( crate ) use foreach_map;
16
+ pub ( crate ) mod macros {
17
+ // The unused_import lint has false-positives around macros
18
+ // https://github.com/rust-lang/rust/issues/78894
19
+ #![ allow( unused_import) ]
42
20
43
- macro_rules! foreach_set {
44
- ( $m: ident) => {
45
- #[ cfg( feature = "alloc" ) ]
46
- $m!( BTreeSet <T : Ord >, ( |_| BTreeSet :: new( ) ) , insert) ;
47
- #[ cfg( feature = "std" ) ]
48
- $m!(
49
- HashSet <T : Eq + Hash , S : BuildHasher + Default >,
50
- ( |size| HashSet :: with_capacity_and_hasher( size, S :: default ( ) ) ) ,
51
- insert
52
- ) ;
53
- #[ cfg( feature = "hashbrown_0_14" ) ]
54
- $m!(
55
- HashbrownSet014 <T : Eq + Hash , S : BuildHasher + Default >,
56
- ( |size| HashbrownSet014 :: with_capacity_and_hasher( size, S :: default ( ) ) ) ,
57
- insert
58
- ) ;
59
- #[ cfg( feature = "indexmap_1" ) ]
60
- $m!(
61
- IndexSet <T : Eq + Hash , S : BuildHasher + Default >,
62
- ( |size| IndexSet :: with_capacity_and_hasher( size, S :: default ( ) ) ) ,
63
- insert
64
- ) ;
65
- #[ cfg( feature = "indexmap_2" ) ]
66
- $m!(
67
- IndexSet2 <T : Eq + Hash , S : BuildHasher + Default >,
68
- ( |size| IndexSet2 :: with_capacity_and_hasher( size, S :: default ( ) ) ) ,
69
- insert
70
- ) ;
71
- } ;
72
- }
73
- pub ( crate ) use foreach_set;
21
+ macro_rules! foreach_map {
22
+ ( $m: ident) => {
23
+ #[ cfg( feature = "alloc" ) ]
24
+ $m!( BTreeMap <K : Ord , V >, ( |_size| BTreeMap :: new( ) ) ) ;
25
+ #[ cfg( feature = "std" ) ]
26
+ $m!(
27
+ HashMap <K : Eq + Hash , V , S : BuildHasher + Default >,
28
+ ( |size| HashMap :: with_capacity_and_hasher( size, Default :: default ( ) ) )
29
+ ) ;
30
+ #[ cfg( feature = "hashbrown_0_14" ) ]
31
+ $m!(
32
+ HashbrownMap014 <K : Eq + Hash , V , S : BuildHasher + Default >,
33
+ ( |size| HashbrownMap014 :: with_capacity_and_hasher( size, Default :: default ( ) ) )
34
+ ) ;
35
+ #[ cfg( feature = "indexmap_1" ) ]
36
+ $m!(
37
+ IndexMap <K : Eq + Hash , V , S : BuildHasher + Default >,
38
+ ( |size| IndexMap :: with_capacity_and_hasher( size, Default :: default ( ) ) )
39
+ ) ;
40
+ #[ cfg( feature = "indexmap_2" ) ]
41
+ $m!(
42
+ IndexMap2 <K : Eq + Hash , V , S : BuildHasher + Default >,
43
+ ( |size| IndexMap2 :: with_capacity_and_hasher( size, Default :: default ( ) ) )
44
+ ) ;
45
+ } ;
46
+ }
74
47
75
- macro_rules! foreach_seq {
76
- ( $m: ident) => {
77
- foreach_set!( $m) ;
48
+ macro_rules! foreach_set {
49
+ ( $m: ident) => {
50
+ #[ cfg( feature = "alloc" ) ]
51
+ $m!( BTreeSet <T : Ord >, ( |_| BTreeSet :: new( ) ) , insert) ;
52
+ #[ cfg( feature = "std" ) ]
53
+ $m!(
54
+ HashSet <T : Eq + Hash , S : BuildHasher + Default >,
55
+ ( |size| HashSet :: with_capacity_and_hasher( size, S :: default ( ) ) ) ,
56
+ insert
57
+ ) ;
58
+ #[ cfg( feature = "hashbrown_0_14" ) ]
59
+ $m!(
60
+ HashbrownSet014 <T : Eq + Hash , S : BuildHasher + Default >,
61
+ ( |size| HashbrownSet014 :: with_capacity_and_hasher( size, S :: default ( ) ) ) ,
62
+ insert
63
+ ) ;
64
+ #[ cfg( feature = "indexmap_1" ) ]
65
+ $m!(
66
+ IndexSet <T : Eq + Hash , S : BuildHasher + Default >,
67
+ ( |size| IndexSet :: with_capacity_and_hasher( size, S :: default ( ) ) ) ,
68
+ insert
69
+ ) ;
70
+ #[ cfg( feature = "indexmap_2" ) ]
71
+ $m!(
72
+ IndexSet2 <T : Eq + Hash , S : BuildHasher + Default >,
73
+ ( |size| IndexSet2 :: with_capacity_and_hasher( size, S :: default ( ) ) ) ,
74
+ insert
75
+ ) ;
76
+ } ;
77
+ }
78
78
79
- #[ cfg( feature = "alloc" ) ]
80
- $m!(
81
- BinaryHeap <T : Ord >,
82
- ( |size| BinaryHeap :: with_capacity( size) ) ,
83
- push
84
- ) ;
85
- #[ cfg( feature = "alloc" ) ]
86
- $m!( BoxedSlice <T >, ( |size| Vec :: with_capacity( size) ) , push) ;
87
- #[ cfg( feature = "alloc" ) ]
88
- $m!( LinkedList <T >, ( |_| LinkedList :: new( ) ) , push_back) ;
89
- #[ cfg( feature = "alloc" ) ]
90
- $m!( Vec <T >, ( |size| Vec :: with_capacity( size) ) , push) ;
91
- #[ cfg( feature = "alloc" ) ]
92
- $m!(
93
- VecDeque <T >,
94
- ( |size| VecDeque :: with_capacity( size) ) ,
95
- push_back
96
- ) ;
97
- } ;
79
+ macro_rules! foreach_seq {
80
+ ( $m: ident) => {
81
+ foreach_set!( $m) ;
82
+
83
+ #[ cfg( feature = "alloc" ) ]
84
+ $m!(
85
+ BinaryHeap <T : Ord >,
86
+ ( |size| BinaryHeap :: with_capacity( size) ) ,
87
+ push
88
+ ) ;
89
+ #[ cfg( feature = "alloc" ) ]
90
+ $m!( BoxedSlice <T >, ( |size| Vec :: with_capacity( size) ) , push) ;
91
+ #[ cfg( feature = "alloc" ) ]
92
+ $m!( LinkedList <T >, ( |_| LinkedList :: new( ) ) , push_back) ;
93
+ #[ cfg( feature = "alloc" ) ]
94
+ $m!( Vec <T >, ( |size| Vec :: with_capacity( size) ) , push) ;
95
+ #[ cfg( feature = "alloc" ) ]
96
+ $m!(
97
+ VecDeque <T >,
98
+ ( |size| VecDeque :: with_capacity( size) ) ,
99
+ push_back
100
+ ) ;
101
+ } ;
102
+ }
103
+
104
+ // Make the macros available to the rest of the crate
105
+ pub ( crate ) use foreach_map;
106
+ pub ( crate ) use foreach_seq;
107
+ pub ( crate ) use foreach_set;
98
108
}
99
109
100
110
///////////////////////////////////////////////////////////////////////////////
0 commit comments