Skip to content

Commit 6b3d1e9

Browse files
committed
add next_index to Enumerate
1 parent efaf4e0 commit 6b3d1e9

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

core/src/iter/adapters/enumerate.rs

+12
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ impl<I> Enumerate<I> {
2323
pub(in crate::iter) fn new(iter: I) -> Enumerate<I> {
2424
Enumerate { iter, count: 0 }
2525
}
26+
27+
/// Retrieve the current position of the iterator.
28+
///
29+
/// If the iterator has not advanced, the position returned will be 0.
30+
///
31+
/// The position may also exceed the bounds of the iterator to allow for calculating
32+
/// the displacement of the iterator from following calls to [`Iterator::next`].
33+
#[inline]
34+
#[unstable(feature = "next_index", issue = "130711")]
35+
pub fn next_index(&self) -> usize {
36+
self.count
37+
}
2638
}
2739

2840
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)