47
47
//! - Enabled by default.
48
48
//! - Enables any item that depend on allocations (like `chunk_by`,
49
49
//! `kmerge`, `join` and many more).
50
+ //! - `hashbrown`
51
+ //! - Disabled by default.
52
+ //! - Enables `use_alloc` and uses `hashbrown::HashMap` instead of
53
+ //! `std::collections::HashMap` to enable some items that depend on hash maps
54
+ //! without `use_std`. It is also possible to use this feature together with
55
+ //! `use_std` if you prefer `hashbrown::HashMap` (for example, because of the
56
+ //! different default hasher).
50
57
//!
51
58
//! ## Rust Version
52
59
//!
@@ -64,15 +71,15 @@ use alloc::{collections::VecDeque, string::String, vec::Vec};
64
71
pub use either:: Either ;
65
72
66
73
use core:: borrow:: Borrow ;
74
+ #[ cfg( feature = "hashbrown" ) ]
75
+ use hashbrown:: { HashMap , HashSet } ;
67
76
use std:: cmp:: Ordering ;
68
- #[ cfg( feature = "use_std" ) ]
69
- use std:: collections:: HashMap ;
70
- #[ cfg( feature = "use_std" ) ]
71
- use std:: collections:: HashSet ;
77
+ #[ cfg( all( feature = "use_std" , not( feature = "hashbrown" ) ) ) ]
78
+ use std:: collections:: { HashMap , HashSet } ;
72
79
use std:: fmt;
73
80
#[ cfg( feature = "use_alloc" ) ]
74
81
use std:: fmt:: Write ;
75
- #[ cfg( feature = "use_std" ) ]
82
+ #[ cfg( any ( feature = "use_std" , feature = "hashbrown" ) ) ]
76
83
use std:: hash:: Hash ;
77
84
use std:: iter:: { once, IntoIterator } ;
78
85
#[ cfg( feature = "use_alloc" ) ]
@@ -102,7 +109,7 @@ pub mod structs {
102
109
#[ cfg( feature = "use_alloc" ) ]
103
110
pub use crate :: combinations_with_replacement:: CombinationsWithReplacement ;
104
111
pub use crate :: cons_tuples_impl:: ConsTuples ;
105
- #[ cfg( feature = "use_std" ) ]
112
+ #[ cfg( any ( feature = "use_std" , feature = "hashbrown" ) ) ]
106
113
pub use crate :: duplicates_impl:: { Duplicates , DuplicatesBy } ;
107
114
pub use crate :: exactly_one_err:: ExactlyOneError ;
108
115
pub use crate :: flatten_ok:: FlattenOk ;
@@ -112,7 +119,7 @@ pub mod structs {
112
119
pub use crate :: groupbylazy:: GroupBy ;
113
120
#[ cfg( feature = "use_alloc" ) ]
114
121
pub use crate :: groupbylazy:: { Chunk , ChunkBy , Chunks , Group , Groups , IntoChunks } ;
115
- #[ cfg( feature = "use_std" ) ]
122
+ #[ cfg( any ( feature = "use_std" , feature = "hashbrown" ) ) ]
116
123
pub use crate :: grouping_map:: { GroupingMap , GroupingMapBy } ;
117
124
pub use crate :: intersperse:: { Intersperse , IntersperseWith } ;
118
125
#[ cfg( feature = "use_alloc" ) ]
@@ -140,7 +147,7 @@ pub mod structs {
140
147
#[ cfg( feature = "use_alloc" ) ]
141
148
pub use crate :: tee:: Tee ;
142
149
pub use crate :: tuple_impl:: { CircularTupleWindows , TupleBuffer , TupleWindows , Tuples } ;
143
- #[ cfg( feature = "use_std" ) ]
150
+ #[ cfg( any ( feature = "use_std" , feature = "hashbrown" ) ) ]
144
151
pub use crate :: unique_impl:: { Unique , UniqueBy } ;
145
152
pub use crate :: with_position:: WithPosition ;
146
153
pub use crate :: zip_eq_impl:: ZipEq ;
@@ -187,18 +194,18 @@ mod combinations_with_replacement;
187
194
mod concat_impl;
188
195
mod cons_tuples_impl;
189
196
mod diff;
190
- #[ cfg( feature = "use_std" ) ]
197
+ #[ cfg( any ( feature = "use_std" , feature = "hashbrown" ) ) ]
191
198
mod duplicates_impl;
192
199
mod exactly_one_err;
193
200
#[ cfg( feature = "use_alloc" ) ]
194
201
mod extrema_set;
195
202
mod flatten_ok;
196
203
mod format;
197
- #[ cfg( feature = "use_alloc" ) ]
204
+ #[ cfg( any ( feature = "use_std" , feature = "hashbrown" ) ) ]
198
205
mod group_map;
199
206
#[ cfg( feature = "use_alloc" ) ]
200
207
mod groupbylazy;
201
- #[ cfg( feature = "use_std" ) ]
208
+ #[ cfg( any ( feature = "use_std" , feature = "hashbrown" ) ) ]
202
209
mod grouping_map;
203
210
mod intersperse;
204
211
mod iter_index;
@@ -233,7 +240,7 @@ mod take_while_inclusive;
233
240
#[ cfg( feature = "use_alloc" ) ]
234
241
mod tee;
235
242
mod tuple_impl;
236
- #[ cfg( feature = "use_std" ) ]
243
+ #[ cfg( any ( feature = "use_std" , feature = "hashbrown" ) ) ]
237
244
mod unique_impl;
238
245
mod unziptuple;
239
246
mod with_position;
@@ -1415,7 +1422,7 @@ pub trait Itertools: Iterator {
1415
1422
/// itertools::assert_equal(data.into_iter().duplicates(),
1416
1423
/// vec![20, 10]);
1417
1424
/// ```
1418
- #[ cfg( feature = "use_std" ) ]
1425
+ #[ cfg( any ( feature = "use_std" , feature = "hashbrown" ) ) ]
1419
1426
fn duplicates ( self ) -> Duplicates < Self >
1420
1427
where
1421
1428
Self : Sized ,
@@ -1441,7 +1448,7 @@ pub trait Itertools: Iterator {
1441
1448
/// itertools::assert_equal(data.into_iter().duplicates_by(|s| s.len()),
1442
1449
/// vec!["aa", "c"]);
1443
1450
/// ```
1444
- #[ cfg( feature = "use_std" ) ]
1451
+ #[ cfg( any ( feature = "use_std" , feature = "hashbrown" ) ) ]
1445
1452
fn duplicates_by < V , F > ( self , f : F ) -> DuplicatesBy < Self , V , F >
1446
1453
where
1447
1454
Self : Sized ,
@@ -1469,7 +1476,7 @@ pub trait Itertools: Iterator {
1469
1476
/// itertools::assert_equal(data.into_iter().unique(),
1470
1477
/// vec![10, 20, 30, 40, 50]);
1471
1478
/// ```
1472
- #[ cfg( feature = "use_std" ) ]
1479
+ #[ cfg( any ( feature = "use_std" , feature = "hashbrown" ) ) ]
1473
1480
fn unique ( self ) -> Unique < Self >
1474
1481
where
1475
1482
Self : Sized ,
@@ -1496,7 +1503,7 @@ pub trait Itertools: Iterator {
1496
1503
/// itertools::assert_equal(data.into_iter().unique_by(|s| s.len()),
1497
1504
/// vec!["a", "bb", "ccc"]);
1498
1505
/// ```
1499
- #[ cfg( feature = "use_std" ) ]
1506
+ #[ cfg( any ( feature = "use_std" , feature = "hashbrown" ) ) ]
1500
1507
fn unique_by < V , F > ( self , f : F ) -> UniqueBy < Self , V , F >
1501
1508
where
1502
1509
Self : Sized ,
@@ -2309,7 +2316,7 @@ pub trait Itertools: Iterator {
2309
2316
/// let data: Option<usize> = None;
2310
2317
/// assert!(data.into_iter().all_unique());
2311
2318
/// ```
2312
- #[ cfg( feature = "use_std" ) ]
2319
+ #[ cfg( any ( feature = "use_std" , feature = "hashbrown" ) ) ]
2313
2320
fn all_unique ( & mut self ) -> bool
2314
2321
where
2315
2322
Self : Sized ,
@@ -3744,7 +3751,7 @@ pub trait Itertools: Iterator {
3744
3751
/// assert_eq!(lookup[&2], vec![12, 42]);
3745
3752
/// assert_eq!(lookup[&3], vec![13, 33]);
3746
3753
/// ```
3747
- #[ cfg( feature = "use_std" ) ]
3754
+ #[ cfg( any ( feature = "use_std" , feature = "hashbrown" ) ) ]
3748
3755
fn into_group_map < K , V > ( self ) -> HashMap < K , Vec < V > >
3749
3756
where
3750
3757
Self : Iterator < Item = ( K , V ) > + Sized ,
@@ -3780,7 +3787,7 @@ pub trait Itertools: Iterator {
3780
3787
/// 30,
3781
3788
/// );
3782
3789
/// ```
3783
- #[ cfg( feature = "use_std" ) ]
3790
+ #[ cfg( any ( feature = "use_std" , feature = "hashbrown" ) ) ]
3784
3791
fn into_group_map_by < K , V , F > ( self , f : F ) -> HashMap < K , Vec < V > >
3785
3792
where
3786
3793
Self : Iterator < Item = V > + Sized ,
@@ -3799,7 +3806,7 @@ pub trait Itertools: Iterator {
3799
3806
///
3800
3807
/// See [`GroupingMap`] for more informations
3801
3808
/// on what operations are available.
3802
- #[ cfg( feature = "use_std" ) ]
3809
+ #[ cfg( any ( feature = "use_std" , feature = "hashbrown" ) ) ]
3803
3810
fn into_grouping_map < K , V > ( self ) -> GroupingMap < Self >
3804
3811
where
3805
3812
Self : Iterator < Item = ( K , V ) > + Sized ,
@@ -3816,7 +3823,7 @@ pub trait Itertools: Iterator {
3816
3823
///
3817
3824
/// See [`GroupingMap`] for more informations
3818
3825
/// on what operations are available.
3819
- #[ cfg( feature = "use_std" ) ]
3826
+ #[ cfg( any ( feature = "use_std" , feature = "hashbrown" ) ) ]
3820
3827
fn into_grouping_map_by < K , V , F > ( self , key_mapper : F ) -> GroupingMapBy < Self , F >
3821
3828
where
3822
3829
Self : Iterator < Item = V > + Sized ,
@@ -4527,7 +4534,7 @@ pub trait Itertools: Iterator {
4527
4534
/// assert_eq!(counts[&5], 1);
4528
4535
/// assert_eq!(counts.get(&0), None);
4529
4536
/// ```
4530
- #[ cfg( feature = "use_std" ) ]
4537
+ #[ cfg( any ( feature = "use_std" , feature = "hashbrown" ) ) ]
4531
4538
fn counts ( self ) -> HashMap < Self :: Item , usize >
4532
4539
where
4533
4540
Self : Sized ,
@@ -4571,7 +4578,7 @@ pub trait Itertools: Iterator {
4571
4578
/// assert_eq!(first_name_frequency["James"], 4);
4572
4579
/// assert_eq!(first_name_frequency.contains_key("Asha"), false);
4573
4580
/// ```
4574
- #[ cfg( feature = "use_std" ) ]
4581
+ #[ cfg( any ( feature = "use_std" , feature = "hashbrown" ) ) ]
4575
4582
fn counts_by < K , F > ( self , f : F ) -> HashMap < K , usize >
4576
4583
where
4577
4584
Self : Sized ,
0 commit comments