Skip to content

Commit de10516

Browse files
committed
Mention array<->tuple convs in docs
1 parent 36f8693 commit de10516

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

library/core/src/primitive_docs.rs

+20
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,9 @@ mod prim_pointer {}
610610
/// if the element type allows it. As a stopgap, trait implementations are
611611
/// statically generated up to size 32.
612612
///
613+
/// Arrays of sizes from 1 to 12 (inclusive) implement [`From<Tuple>`], where `Tuple`
614+
/// is a homogenous [prim@tuple] of appropriate length.
615+
///
613616
/// Arrays coerce to [slices (`[T]`)][slice], so a slice method may be called on
614617
/// an array. Indeed, this provides most of the API for working with arrays.
615618
///
@@ -672,6 +675,13 @@ mod prim_pointer {}
672675
/// move_away(roa);
673676
/// ```
674677
///
678+
/// Arrays can be created from homogenous tuples of appropriate length:
679+
///
680+
/// ```
681+
/// let tuple: (u32, u32, u32) = (1, 2, 3);
682+
/// let array: [u32; 3] = tuple.into();
683+
/// ```
684+
///
675685
/// # Editions
676686
///
677687
/// Prior to Rust 1.53, arrays did not implement [`IntoIterator`] by value, so the method call
@@ -774,6 +784,7 @@ mod prim_pointer {}
774784
/// [`Borrow`]: borrow::Borrow
775785
/// [`BorrowMut`]: borrow::BorrowMut
776786
/// [slice pattern]: ../reference/patterns.html#slice-patterns
787+
/// [`From<Tuple>`]: convert::From
777788
#[stable(feature = "rust1", since = "1.0.0")]
778789
mod prim_array {}
779790

@@ -1000,7 +1011,9 @@ mod prim_str {}
10001011
/// * [`Debug`]
10011012
/// * [`Default`]
10021013
/// * [`Hash`]
1014+
/// * [`From<[T; N]>`][from]
10031015
///
1016+
/// [from]: convert::From
10041017
/// [`Debug`]: fmt::Debug
10051018
/// [`Hash`]: hash::Hash
10061019
///
@@ -1051,6 +1064,13 @@ mod prim_str {}
10511064
/// assert_eq!(y, 5);
10521065
/// ```
10531066
///
1067+
/// Homogenous tuples can be created from arrays of appropriate length:
1068+
///
1069+
/// ```
1070+
/// let array: [u32; 3] = [1, 2, 3];
1071+
/// let tuple: (u32, u32, u32) = array.into();
1072+
/// ```
1073+
///
10541074
#[stable(feature = "rust1", since = "1.0.0")]
10551075
mod prim_tuple {}
10561076

library/std/src/primitive_docs.rs

+20
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,9 @@ mod prim_pointer {}
610610
/// if the element type allows it. As a stopgap, trait implementations are
611611
/// statically generated up to size 32.
612612
///
613+
/// Arrays of sizes from 1 to 12 (inclusive) implement [`From<Tuple>`], where `Tuple`
614+
/// is a homogenous [prim@tuple] of appropriate length.
615+
///
613616
/// Arrays coerce to [slices (`[T]`)][slice], so a slice method may be called on
614617
/// an array. Indeed, this provides most of the API for working with arrays.
615618
///
@@ -672,6 +675,13 @@ mod prim_pointer {}
672675
/// move_away(roa);
673676
/// ```
674677
///
678+
/// Arrays can be created from homogenous tuples of appropriate length:
679+
///
680+
/// ```
681+
/// let tuple: (u32, u32, u32) = (1, 2, 3);
682+
/// let array: [u32; 3] = tuple.into();
683+
/// ```
684+
///
675685
/// # Editions
676686
///
677687
/// Prior to Rust 1.53, arrays did not implement [`IntoIterator`] by value, so the method call
@@ -774,6 +784,7 @@ mod prim_pointer {}
774784
/// [`Borrow`]: borrow::Borrow
775785
/// [`BorrowMut`]: borrow::BorrowMut
776786
/// [slice pattern]: ../reference/patterns.html#slice-patterns
787+
/// [`From<Tuple>`]: convert::From
777788
#[stable(feature = "rust1", since = "1.0.0")]
778789
mod prim_array {}
779790

@@ -1000,7 +1011,9 @@ mod prim_str {}
10001011
/// * [`Debug`]
10011012
/// * [`Default`]
10021013
/// * [`Hash`]
1014+
/// * [`From<[T; N]>`][from]
10031015
///
1016+
/// [from]: convert::From
10041017
/// [`Debug`]: fmt::Debug
10051018
/// [`Hash`]: hash::Hash
10061019
///
@@ -1051,6 +1064,13 @@ mod prim_str {}
10511064
/// assert_eq!(y, 5);
10521065
/// ```
10531066
///
1067+
/// Homogenous tuples can be created from arrays of appropriate length:
1068+
///
1069+
/// ```
1070+
/// let array: [u32; 3] = [1, 2, 3];
1071+
/// let tuple: (u32, u32, u32) = array.into();
1072+
/// ```
1073+
///
10541074
#[stable(feature = "rust1", since = "1.0.0")]
10551075
mod prim_tuple {}
10561076

0 commit comments

Comments
 (0)