about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNilstrieb <48135649+Nilstrieb@users.noreply.github.com>2022-05-16 19:29:45 +0200
committerNilstrieb <48135649+Nilstrieb@users.noreply.github.com>2022-05-16 19:29:45 +0200
commit4a2214885d469b27624df33145863037ca148f56 (patch)
tree3934a3f26f875da93995ad42f2a9b586c2199cfb
parentc52b9c10bfb5164015eb977ff498e0597ae63eb1 (diff)
downloadrust-4a2214885d469b27624df33145863037ca148f56.tar.gz
rust-4a2214885d469b27624df33145863037ca148f56.zip
Clarify slice and Vec iteration order
While already being inferable from the doc examples, it wasn't
fully specified. This is the only logical way to do a slice
iterator.
-rw-r--r--library/alloc/src/vec/mod.rs11
-rw-r--r--library/core/src/slice/mod.rs4
2 files changed, 11 insertions, 4 deletions
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs
index 3dc8a4fbba8..a1fd9e8de59 100644
--- a/library/alloc/src/vec/mod.rs
+++ b/library/alloc/src/vec/mod.rs
@@ -2626,10 +2626,13 @@ impl<T, A: Allocator> IntoIterator for Vec<T, A> {
     ///
     /// ```
     /// let v = vec!["a".to_string(), "b".to_string()];
-    /// for s in v.into_iter() {
-    ///     // s has type String, not &String
-    ///     println!("{s}");
-    /// }
+    /// let mut v_iter = v.into_iter();
+    ///
+    /// let first_element: Option<String> = v_iter.next();
+    ///
+    /// assert_eq!(first_element, Some("a".to_string()));
+    /// assert_eq!(v_iter.next(), Some("b".to_string()));
+    /// assert_eq!(v_iter.next(), None);
     /// ```
     #[inline]
     fn into_iter(self) -> IntoIter<T, A> {
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs
index a226dea54a4..7aedea48008 100644
--- a/library/core/src/slice/mod.rs
+++ b/library/core/src/slice/mod.rs
@@ -716,6 +716,8 @@ impl<T> [T] {
 
     /// Returns an iterator over the slice.
     ///
+    /// The iterator yields all items from start to end.
+    ///
     /// # Examples
     ///
     /// ```
@@ -735,6 +737,8 @@ impl<T> [T] {
 
     /// Returns an iterator that allows modifying each value.
     ///
+    /// The iterator yields all items from start to end.
+    ///
     /// # Examples
     ///
     /// ```