diff options
| author | Lukas Kalbertodt <lukas.kalbertodt@gmail.com> | 2020-07-28 19:03:56 +0200 |
|---|---|---|
| committer | Josh Stone <jistone@redhat.com> | 2021-04-16 11:12:01 -0700 |
| commit | 35b1590223b44a7da28c584c97967cc63f3e4e25 (patch) | |
| tree | 5b94889f3a0f3ace1a3dd2e6d907096f0493083e /library/std/src | |
| parent | 32aaea9c8fb99a94e6b289498a348459357c392f (diff) | |
| download | rust-35b1590223b44a7da28c584c97967cc63f3e4e25.tar.gz rust-35b1590223b44a7da28c584c97967cc63f3e4e25.zip | |
Adjust docs and tests for new `IntoIterator` impl for arrays
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/primitive_docs.rs | 23 |
1 files changed, 4 insertions, 19 deletions
diff --git a/library/std/src/primitive_docs.rs b/library/std/src/primitive_docs.rs index 64b22b64f4b..ad4737ec2f6 100644 --- a/library/std/src/primitive_docs.rs +++ b/library/std/src/primitive_docs.rs @@ -498,7 +498,7 @@ mod prim_pointer {} /// - [`Copy`] /// - [`Clone`] /// - [`Debug`] -/// - [`IntoIterator`] (implemented for `&[T; N]` and `&mut [T; N]`) +/// - [`IntoIterator`] (implemented for `[T; N]`, `&[T; N]` and `&mut [T; N]`) /// - [`PartialEq`], [`PartialOrd`], [`Eq`], [`Ord`] /// - [`Hash`] /// - [`AsRef`], [`AsMut`] @@ -526,31 +526,16 @@ mod prim_pointer {} /// assert_eq!([1, 2], &array[1..]); /// /// // This loop prints: 0 1 2 -/// for x in &array { +/// for x in array { /// print!("{} ", x); /// } /// ``` /// -/// An array itself is not iterable: -/// -/// ```compile_fail,E0277 -/// let array: [i32; 3] = [0; 3]; -/// -/// for x in array { } -/// // error: the trait bound `[i32; 3]: std::iter::Iterator` is not satisfied -/// ``` -/// -/// The solution is to coerce the array to a slice by calling a slice method: +/// You can also iterate over reference to the array's elements: /// /// ``` -/// # let array: [i32; 3] = [0; 3]; -/// for x in array.iter() { } -/// ``` -/// -/// You can also use the array reference's [`IntoIterator`] implementation: +/// let array: [i32; 3] = [0; 3]; /// -/// ``` -/// # let array: [i32; 3] = [0; 3]; /// for x in &array { } /// ``` /// |
