4
4
///
5
5
/// ```
6
6
/// use indexmap::indexmap_with_hasher;
7
- /// use std::collections::hash_map::RandomState ;
7
+ /// use std::hash::DefaultHasher ;
8
8
///
9
9
/// let map = indexmap_with_hasher!{
10
- /// RandomState ;
10
+ /// DefaultHasher ;
11
11
/// "a" => 1,
12
12
/// "b" => 2,
13
13
/// };
22
22
macro_rules! indexmap_with_hasher {
23
23
( $S: ty; $( $key: expr => $value: expr, ) +) => { $crate:: indexmap_with_hasher!( $S; $( $key => $value) ,+) } ;
24
24
( $S: ty; $( $key: expr => $value: expr) ,* ) => { {
25
+ type BuildS = core:: hash:: BuildHasherDefault <$S>;
25
26
const CAP : usize = <[ ( ) ] >:: len( & [ $( { stringify!( $key) ; } ) ,* ] ) ;
26
27
#[ allow( unused_mut) ]
27
- // Specify your custom S (must implement Default) as the hasher:
28
- let mut map = $crate:: IndexMap :: <_, _, $S >:: with_capacity_and_hasher( CAP , <$S >:: default ( ) ) ;
28
+ // Specify your custom S (must implement Default + Hasher ) as the hasher:
29
+ let mut map = $crate:: IndexMap :: <_, _, BuildS >:: with_capacity_and_hasher( CAP , <BuildS >:: default ( ) ) ;
29
30
$(
30
31
map. insert( $key, $value) ;
31
32
) *
@@ -76,10 +77,10 @@ macro_rules! indexmap {
76
77
///
77
78
/// ```
78
79
/// use indexmap::indexset_with_hasher;
79
- /// use std::collections::hash_map::RandomState ;
80
+ /// use std::hash::DefaultHasher ;
80
81
///
81
82
/// let set = indexset_with_hasher!{
82
- /// RandomState ;
83
+ /// DefaultHasher ;
83
84
/// "a",
84
85
/// "b",
85
86
/// };
@@ -94,10 +95,11 @@ macro_rules! indexmap {
94
95
macro_rules! indexset_with_hasher {
95
96
( $S: ty; $( $value: expr, ) +) => { $crate:: indexset_with_hasher!( $S; $( $value) ,+) } ;
96
97
( $S: ty; $( $value: expr) ,* ) => { {
98
+ type BuildS = core:: hash:: BuildHasherDefault <$S>;
97
99
const CAP : usize = <[ ( ) ] >:: len( & [ $( { stringify!( $value) ; } ) ,* ] ) ;
98
100
#[ allow( unused_mut) ]
99
101
// Specify your custom S (must implement Default) as the hasher:
100
- let mut set = $crate:: IndexSet :: <_, $S >:: with_capacity_and_hasher( CAP , <$S >:: default ( ) ) ;
102
+ let mut set = $crate:: IndexSet :: <_, BuildS >:: with_capacity_and_hasher( CAP , <BuildS >:: default ( ) ) ;
101
103
$(
102
104
set. insert( $value) ;
103
105
) *
0 commit comments