Skip to content

Commit af971f3

Browse files
committed
Add T to bucket iterators and inline their methods
1 parent 7ccb6d6 commit af971f3

File tree

1 file changed

+57
-15
lines changed

1 file changed

+57
-15
lines changed

src/table.rs

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ where
11001100
/// # test()
11011101
/// # }
11021102
/// ```
1103-
pub fn iter_buckets(&self) -> IterBuckets<'_> {
1103+
pub fn iter_buckets(&self) -> IterBuckets<'_, T> {
11041104
IterBuckets {
11051105
inner: unsafe { self.raw.full_buckets_indices() },
11061106
marker: PhantomData,
@@ -1233,7 +1233,7 @@ where
12331233
/// # test()
12341234
/// # }
12351235
/// ```
1236-
pub fn iter_hash_buckets(&self, hash: u64) -> IterHashBuckets<'_> {
1236+
pub fn iter_hash_buckets(&self, hash: u64) -> IterHashBuckets<'_, T> {
12371237
IterHashBuckets {
12381238
inner: unsafe { self.raw.iter_hash_buckets(hash) },
12391239
marker: PhantomData,
@@ -2569,33 +2569,55 @@ where
25692569
///
25702570
/// This `struct` is created by the [`HashTable::iter_buckets`] method. See its
25712571
/// documentation for more.
2572-
#[derive(Clone, Default)]
2573-
pub struct IterBuckets<'a> {
2572+
pub struct IterBuckets<'a, T> {
25742573
inner: FullBucketsIndices,
2575-
marker: PhantomData<&'a ()>,
2574+
marker: PhantomData<&'a T>,
25762575
}
25772576

2578-
impl Iterator for IterBuckets<'_> {
2577+
impl<T> Clone for IterBuckets<'_, T> {
2578+
#[inline]
2579+
fn clone(&self) -> Self {
2580+
Self {
2581+
inner: self.inner.clone(),
2582+
marker: PhantomData,
2583+
}
2584+
}
2585+
}
2586+
2587+
impl<T> Default for IterBuckets<'_, T> {
2588+
#[inline]
2589+
fn default() -> Self {
2590+
Self {
2591+
inner: Default::default(),
2592+
marker: PhantomData,
2593+
}
2594+
}
2595+
}
2596+
2597+
impl<T> Iterator for IterBuckets<'_, T> {
25792598
type Item = usize;
25802599

2600+
#[inline]
25812601
fn next(&mut self) -> Option<usize> {
25822602
self.inner.next()
25832603
}
25842604

2605+
#[inline]
25852606
fn size_hint(&self) -> (usize, Option<usize>) {
25862607
self.inner.size_hint()
25872608
}
25882609
}
25892610

2590-
impl ExactSizeIterator for IterBuckets<'_> {
2611+
impl<T> ExactSizeIterator for IterBuckets<'_, T> {
2612+
#[inline]
25912613
fn len(&self) -> usize {
25922614
self.inner.len()
25932615
}
25942616
}
25952617

2596-
impl FusedIterator for IterBuckets<'_> {}
2618+
impl<T> FusedIterator for IterBuckets<'_, T> {}
25972619

2598-
impl fmt::Debug for IterBuckets<'_> {
2620+
impl<T> fmt::Debug for IterBuckets<'_, T> {
25992621
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26002622
f.debug_list().entries(self.clone()).finish()
26012623
}
@@ -2731,23 +2753,43 @@ where
27312753
///
27322754
/// This `struct` is created by the [`HashTable::iter_hash_buckets`] method. See its
27332755
/// documentation for more.
2734-
#[derive(Clone, Default)]
2735-
pub struct IterHashBuckets<'a> {
2756+
pub struct IterHashBuckets<'a, T> {
27362757
inner: RawIterHashIndices,
2737-
marker: PhantomData<&'a ()>,
2758+
marker: PhantomData<&'a T>,
2759+
}
2760+
2761+
impl<T> Clone for IterHashBuckets<'_, T> {
2762+
#[inline]
2763+
fn clone(&self) -> Self {
2764+
Self {
2765+
inner: self.inner.clone(),
2766+
marker: PhantomData,
2767+
}
2768+
}
27382769
}
27392770

2740-
impl Iterator for IterHashBuckets<'_> {
2771+
impl<T> Default for IterHashBuckets<'_, T> {
2772+
#[inline]
2773+
fn default() -> Self {
2774+
Self {
2775+
inner: Default::default(),
2776+
marker: PhantomData,
2777+
}
2778+
}
2779+
}
2780+
2781+
impl<T> Iterator for IterHashBuckets<'_, T> {
27412782
type Item = usize;
27422783

2784+
#[inline]
27432785
fn next(&mut self) -> Option<Self::Item> {
27442786
self.inner.next()
27452787
}
27462788
}
27472789

2748-
impl FusedIterator for IterHashBuckets<'_> {}
2790+
impl<T> FusedIterator for IterHashBuckets<'_, T> {}
27492791

2750-
impl fmt::Debug for IterHashBuckets<'_> {
2792+
impl<T> fmt::Debug for IterHashBuckets<'_, T> {
27512793
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27522794
f.debug_list().entries(self.clone()).finish()
27532795
}

0 commit comments

Comments
 (0)