Adjust docs and tests for new IntoIterator
impl for arrays
This commit is contained in:
parent
32aaea9c8f
commit
35b1590223
5 changed files with 8 additions and 169 deletions
|
@ -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:
|
||||
/// You can also iterate over reference to the array's elements:
|
||||
///
|
||||
/// ```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:
|
||||
///
|
||||
/// ```
|
||||
/// # 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];
|
||||
/// for x in &array { }
|
||||
/// ```
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue