about summary refs log tree commit diff
path: root/library/alloc/src/vec
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-05-23 07:43:49 +0200
committerGitHub <noreply@github.com>2022-05-23 07:43:49 +0200
commite5cf3cb97d228f7c5ac691ebf3f754bec5a92852 (patch)
tree8c634cf1808bd1d68298fa82e72eaca89445a69e /library/alloc/src/vec
parentc186f7c07912064c352f12d8b0aa9d5e5975450e (diff)
parent4a2214885d469b27624df33145863037ca148f56 (diff)
downloadrust-e5cf3cb97d228f7c5ac691ebf3f754bec5a92852.tar.gz
rust-e5cf3cb97d228f7c5ac691ebf3f754bec5a92852.zip
Rollup merge of #97087 - Nilstrieb:clarify-slice-iteration-order, r=dtolnay
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, so I think this should be uncontroversial. It also improves the `Vec::into_iter` example to better show the order and that the iterator returns owned values.
Diffstat (limited to 'library/alloc/src/vec')
-rw-r--r--library/alloc/src/vec/mod.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs
index 62bc04cadee..c157aba83c2 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> {