about summary refs log tree commit diff
path: root/library/core/src
diff options
context:
space:
mode:
authorJonathan Gruner <jogru0@gmail.com>2025-04-19 12:06:30 +0200
committerJonathan Gruner <jogru0@gmail.com>2025-04-19 12:29:47 +0200
commit5a71fabe297ab172eb873a03ab5e057ca55f78db (patch)
treedeb22ab9decd5a95016b859eb73d7baea8d05db2 /library/core/src
parent1f491dccba0d593ba6ba87ae830a59e571b9309f (diff)
downloadrust-5a71fabe297ab172eb873a03ab5e057ca55f78db.tar.gz
rust-5a71fabe297ab172eb873a03ab5e057ca55f78db.zip
added doctest for Enumerate::next_index
Diffstat (limited to 'library/core/src')
-rw-r--r--library/core/src/iter/adapters/enumerate.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/library/core/src/iter/adapters/enumerate.rs b/library/core/src/iter/adapters/enumerate.rs
index 1f2cf3244b3..f7b9f0b7a5e 100644
--- a/library/core/src/iter/adapters/enumerate.rs
+++ b/library/core/src/iter/adapters/enumerate.rs
@@ -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 {