Skip to content

Commit f5e95cb

Browse files
committed
added doctest for Enumerate::next_index
1 parent 6b3d1e9 commit f5e95cb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

core/src/iter/adapters/enumerate.rs

+21
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,27 @@ impl<I> Enumerate<I> {
3030
///
3131
/// The position may also exceed the bounds of the iterator to allow for calculating
3232
/// the displacement of the iterator from following calls to [`Iterator::next`].
33+
///
34+
/// # Examples
35+
///
36+
/// ```
37+
/// #![feature(next_index)]
38+
///
39+
/// let arr = ['a', 'b'];
40+
///
41+
/// let mut iter = arr.iter().enumerate();
42+
///
43+
/// assert_eq!(iter.next_index(), 0);
44+
/// assert_eq!(iter.next(), Some((0, &'a')));
45+
///
46+
/// assert_eq!(iter.next_index(), 1);
47+
/// assert_eq!(iter.next_index(), 1);
48+
/// assert_eq!(iter.next(), Some((1, &'b')));
49+
///
50+
/// assert_eq!(iter.next_index(), 2);
51+
/// assert_eq!(iter.next(), None);
52+
/// assert_eq!(iter.next_index(), 2);
53+
/// ```
3354
#[inline]
3455
#[unstable(feature = "next_index", issue = "130711")]
3556
pub fn next_index(&self) -> usize {

0 commit comments

Comments
 (0)