Skip to content

Commit eedabac

Browse files
authored
Merge pull request #251 from cuviper/more-slicing
Add more slicing methods to iterators, like std
2 parents beb7966 + a45f31e commit eedabac

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/map/iter.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ impl<'a, K, V> IterMut<'a, K, V> {
108108
}
109109

110110
/// Returns a slice of the remaining entries in the iterator.
111+
pub fn as_slice(&self) -> &Slice<K, V> {
112+
Slice::from_slice(self.iter.as_slice())
113+
}
114+
115+
/// Returns a mutable slice of the remaining entries in the iterator.
111116
///
112117
/// To avoid creating `&mut` references that alias, this is forced to consume the iterator.
113118
pub fn into_slice(self) -> &'a mut Slice<K, V> {
@@ -157,6 +162,16 @@ impl<K, V> IntoIter<K, V> {
157162
iter: entries.into_iter(),
158163
}
159164
}
165+
166+
/// Returns a slice of the remaining entries in the iterator.
167+
pub fn as_slice(&self) -> &Slice<K, V> {
168+
Slice::from_slice(self.iter.as_slice())
169+
}
170+
171+
/// Returns a mutable slice of the remaining entries in the iterator.
172+
pub fn as_mut_slice(&mut self) -> &mut Slice<K, V> {
173+
Slice::from_mut_slice(self.iter.as_mut_slice())
174+
}
160175
}
161176

162177
impl<K, V> Iterator for IntoIter<K, V> {
@@ -199,6 +214,11 @@ impl<'a, K, V> Drain<'a, K, V> {
199214
pub(super) fn new(iter: vec::Drain<'a, Bucket<K, V>>) -> Self {
200215
Self { iter }
201216
}
217+
218+
/// Returns a slice of the remaining entries in the iterator.
219+
pub fn as_slice(&self) -> &Slice<K, V> {
220+
Slice::from_slice(self.iter.as_slice())
221+
}
202222
}
203223

204224
impl<K, V> Iterator for Drain<'_, K, V> {

src/set/iter.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ impl<T> IntoIter<T> {
9797
iter: entries.into_iter(),
9898
}
9999
}
100+
101+
/// Returns a slice of the remaining entries in the iterator.
102+
pub fn as_slice(&self) -> &Slice<T> {
103+
Slice::from_slice(self.iter.as_slice())
104+
}
100105
}
101106

102107
impl<T> Iterator for IntoIter<T> {
@@ -139,6 +144,11 @@ impl<'a, T> Drain<'a, T> {
139144
pub(super) fn new(iter: vec::Drain<'a, Bucket<T>>) -> Self {
140145
Self { iter }
141146
}
147+
148+
/// Returns a slice of the remaining entries in the iterator.
149+
pub fn as_slice(&self) -> &Slice<T> {
150+
Slice::from_slice(self.iter.as_slice())
151+
}
142152
}
143153

144154
impl<T> Iterator for Drain<'_, T> {

0 commit comments

Comments
 (0)