Skip to content

Commit

Permalink
Clarify slice and Vec iteration order
Browse files Browse the repository at this point in the history
While already being inferable from the doc examples, it wasn't
fully specified. This is the only logical way to do a slice
iterator.
  • Loading branch information
Noratrieb committed May 16, 2022
1 parent c52b9c1 commit 4a22148
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 7 additions & 4 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,8 @@ impl<T> [T] {

/// Returns an iterator over the slice.
///
/// The iterator yields all items from start to end.
///
/// # Examples
///
/// ```
Expand All @@ -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
///
/// ```
Expand Down

0 comments on commit 4a22148

Please sign in to comment.