Skip to content

Commit c5e7b1f

Browse files
committed
make Drain and DrainFilter independent of ArrayTable
1 parent 001b55e commit c5e7b1f

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

src/array_map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ where
639639
///
640640
/// assert_eq!(drained, [None, None, None, Some(("rust", "rost")),]);
641641
/// ```
642-
pub fn drain_filter<F>(&mut self, f: F) -> DrainFilter<'_, K, V, F, B, N>
642+
pub fn drain_filter<F>(&mut self, f: F) -> DrainFilter<'_, K, V, F, ArrayTable<(K, V), N>, B>
643643
where
644644
F: FnMut(&K, &mut V) -> bool,
645645
{
@@ -672,7 +672,7 @@ where
672672
/// ]
673673
/// );
674674
/// ```
675-
pub fn drain(&mut self) -> Drain<'_, K, V, B, N> {
675+
pub fn drain(&mut self) -> Drain<'_, K, V, ArrayTable<(K, V), N>, B> {
676676
Drain::new(&mut self.table, &self.build_hasher)
677677
}
678678

src/iter/drain.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,41 @@
11
use core::hash::{BuildHasher, Hash};
22

33
use super::DrainFilter;
4-
use crate::raw::ArrayTable;
4+
use crate::raw::RawTable;
55

66
/// A draining iterator over entries of an `ArrayMap`.
77
///
88
/// This struct is created by [`ArrayMap::drain`]. See its documentation for
99
/// more.
1010
///
1111
/// [`ArrayMap::drain`]: crate::ArrayMap::drain
12-
pub struct Drain<'a, K, V, B: BuildHasher, const N: usize>
12+
pub struct Drain<'a, K, V, R, B>
1313
where
1414
K: Hash + Eq,
15+
R: RawTable<(K, V)>,
16+
B: BuildHasher,
1517
{
16-
inner: DrainFilter<'a, K, V, fn(&K, &mut V) -> bool, B, N>,
18+
inner: DrainFilter<'a, K, V, fn(&K, &mut V) -> bool, R, B>,
1719
}
1820

19-
impl<'a, K, V, B: BuildHasher, const N: usize> Drain<'a, K, V, B, N>
21+
impl<'a, K, V, R, B> Drain<'a, K, V, R, B>
2022
where
2123
K: Hash + Eq,
24+
R: RawTable<(K, V)>,
25+
B: BuildHasher,
2226
{
23-
pub(crate) fn new(table: &'a mut ArrayTable<(K, V), N>, build_hasher: &'a B) -> Self {
27+
pub(crate) fn new(table: &'a mut R, build_hasher: &'a B) -> Self {
2428
Self {
2529
inner: DrainFilter::new(|_, _| true, table, build_hasher),
2630
}
2731
}
2832
}
2933

30-
impl<'a, K, V, B: BuildHasher, const N: usize> Iterator for Drain<'a, K, V, B, N>
34+
impl<'a, K, V, R, B> Iterator for Drain<'a, K, V, R, B>
3135
where
3236
K: Eq + Hash,
37+
R: RawTable<(K, V)>,
38+
B: BuildHasher,
3339
{
3440
type Item = (K, V);
3541

src/iter/drain_filter.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use core::hash::{BuildHasher, Hash};
22
use core::mem;
33

4-
use crate::raw::{ArrayTable, RawTable};
4+
use crate::raw::RawTable;
55
use crate::utils;
66

77
/// A draining iterator over entries of an `ArrayMap` which do not satisfy the
@@ -11,23 +11,27 @@ use crate::utils;
1111
/// for more.
1212
///
1313
/// [`ArrayMap::drain_filter`]: crate::ArrayMap::drain_filter
14-
pub struct DrainFilter<'a, K, V, F, B: BuildHasher, const N: usize>
14+
pub struct DrainFilter<'a, K, V, F, R, B>
1515
where
16+
B: BuildHasher,
1617
F: FnMut(&K, &mut V) -> bool,
1718
K: Hash + Eq,
19+
R: RawTable<(K, V)>,
1820
{
1921
f: F,
20-
iter: <ArrayTable<(K, V), N> as RawTable<(K, V)>>::RawIter,
21-
table: &'a mut ArrayTable<(K, V), N>,
22+
iter: R::RawIter,
23+
table: &'a mut R,
2224
build_hasher: &'a B,
2325
}
2426

25-
impl<'a, K, V, F, B: BuildHasher, const N: usize> DrainFilter<'a, K, V, F, B, N>
27+
impl<'a, K, V, F, R, B> DrainFilter<'a, K, V, F, R, B>
2628
where
29+
B: BuildHasher,
2730
F: FnMut(&K, &mut V) -> bool,
2831
K: Hash + Eq,
32+
R: RawTable<(K, V)>,
2933
{
30-
pub(crate) fn new(f: F, table: &'a mut ArrayTable<(K, V), N>, build_hasher: &'a B) -> Self {
34+
pub(crate) fn new(f: F, table: &'a mut R, build_hasher: &'a B) -> Self {
3135
Self {
3236
f,
3337
iter: table.iter(),
@@ -37,10 +41,12 @@ where
3741
}
3842
}
3943

40-
impl<'a, K, V, F, B: BuildHasher, const N: usize> Iterator for DrainFilter<'a, K, V, F, B, N>
44+
impl<'a, K, V, F, R, B> Iterator for DrainFilter<'a, K, V, F, R, B>
4145
where
46+
B: BuildHasher,
4247
F: FnMut(&K, &mut V) -> bool,
4348
K: Eq + Hash,
49+
R: RawTable<(K, V)>,
4450
{
4551
type Item = (K, V);
4652

@@ -60,11 +66,12 @@ where
6066
}
6167
}
6268

63-
impl<'a, K, V, F, B, const N: usize> Drop for DrainFilter<'a, K, V, F, B, N>
69+
impl<'a, K, V, F, R, B> Drop for DrainFilter<'a, K, V, F, R, B>
6470
where
6571
B: BuildHasher,
6672
F: FnMut(&K, &mut V) -> bool,
6773
K: Eq + Hash,
74+
R: RawTable<(K, V)>,
6875
{
6976
fn drop(&mut self) {
7077
self.for_each(mem::drop);

0 commit comments

Comments
 (0)