Skip to content

Commit 4a22148

Browse files
committed
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.
1 parent c52b9c1 commit 4a22148

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

library/alloc/src/vec/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -2626,10 +2626,13 @@ impl<T, A: Allocator> IntoIterator for Vec<T, A> {
26262626
///
26272627
/// ```
26282628
/// let v = vec!["a".to_string(), "b".to_string()];
2629-
/// for s in v.into_iter() {
2630-
/// // s has type String, not &String
2631-
/// println!("{s}");
2632-
/// }
2629+
/// let mut v_iter = v.into_iter();
2630+
///
2631+
/// let first_element: Option<String> = v_iter.next();
2632+
///
2633+
/// assert_eq!(first_element, Some("a".to_string()));
2634+
/// assert_eq!(v_iter.next(), Some("b".to_string()));
2635+
/// assert_eq!(v_iter.next(), None);
26332636
/// ```
26342637
#[inline]
26352638
fn into_iter(self) -> IntoIter<T, A> {

library/core/src/slice/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,8 @@ impl<T> [T] {
716716

717717
/// Returns an iterator over the slice.
718718
///
719+
/// The iterator yields all items from start to end.
720+
///
719721
/// # Examples
720722
///
721723
/// ```
@@ -735,6 +737,8 @@ impl<T> [T] {
735737

736738
/// Returns an iterator that allows modifying each value.
737739
///
740+
/// The iterator yields all items from start to end.
741+
///
738742
/// # Examples
739743
///
740744
/// ```

0 commit comments

Comments
 (0)