From 4a2214885d469b27624df33145863037ca148f56 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Mon, 16 May 2022 19:29:45 +0200 Subject: [PATCH] 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. --- library/alloc/src/vec/mod.rs | 11 +++++++---- library/core/src/slice/mod.rs | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 3dc8a4fbba86b..a1fd9e8de595e 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2626,10 +2626,13 @@ impl IntoIterator for Vec { /// /// ``` /// 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 = 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 { diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index a226dea54a4f2..7aedea48008c5 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -716,6 +716,8 @@ impl [T] { /// Returns an iterator over the slice. /// + /// The iterator yields all items from start to end. + /// /// # Examples /// /// ``` @@ -735,6 +737,8 @@ impl [T] { /// Returns an iterator that allows modifying each value. /// + /// The iterator yields all items from start to end. + /// /// # Examples /// /// ```