mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
added doctest for Enumerate::next_index
This commit is contained in:
parent
1f491dccba
commit
5a71fabe29
@ -30,6 +30,27 @@ impl<I> Enumerate<I> {
|
||||
///
|
||||
/// The position may also exceed the bounds of the iterator to allow for calculating
|
||||
/// the displacement of the iterator from following calls to [`Iterator::next`].
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(next_index)]
|
||||
///
|
||||
/// let arr = ['a', 'b'];
|
||||
///
|
||||
/// let mut iter = arr.iter().enumerate();
|
||||
///
|
||||
/// assert_eq!(iter.next_index(), 0);
|
||||
/// assert_eq!(iter.next(), Some((0, &'a')));
|
||||
///
|
||||
/// assert_eq!(iter.next_index(), 1);
|
||||
/// assert_eq!(iter.next_index(), 1);
|
||||
/// assert_eq!(iter.next(), Some((1, &'b')));
|
||||
///
|
||||
/// assert_eq!(iter.next_index(), 2);
|
||||
/// assert_eq!(iter.next(), None);
|
||||
/// assert_eq!(iter.next_index(), 2);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "next_index", issue = "130711")]
|
||||
pub fn next_index(&self) -> usize {
|
||||
|
Loading…
Reference in New Issue
Block a user