Skip to content

Commit 1abdd13

Browse files
committed
Expand documentation for the primitive type array
1 parent 6c4e236 commit 1abdd13

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

src/libstd/array.rs

+35-6
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,48 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! The fixed-size array type (`[T; n]`).
11+
//! A fixed-size array is denoted `[T; N]` for the element type `T` and
12+
//! the compile time constant size `N`. The size should be zero or positive.
1213
//!
13-
//! Some usage examples:
14+
//! Arrays values are created either with an explicit expression that lists
15+
//! each element: `[x, y, z]` or a repeat expression: `[x; N]`. The repeat
16+
//! expression requires that the element type is `Copy`.
17+
//!
18+
//! The type `[T; N]` is `Copy` if `T: Copy`.
19+
//!
20+
//! Arrays of sizes from 0 to 32 (inclusive) implement the following traits
21+
//! if the element type allows it:
22+
//!
23+
//! - `Clone`
24+
//! - `Debug`
25+
//! - `IntoIterator` (implemented for `&[T; N]` and `&mut [T; N]`)
26+
//! - `PartialEq`, `PartialOrd`, `Ord`, `Eq`
27+
//! - `Hash`
28+
//! - `AsRef`, `AsMut`
29+
//!
30+
//! Arrays dereference to [slices (`[T]`)][slice], so their methods can be called
31+
//! on arrays.
32+
//!
33+
//! [slice]: primitive.slice.html
34+
//!
35+
//! ## Examples
1436
//!
1537
//! ```
16-
//! let array: [i32; 3] = [0, 1, 2];
38+
//! let mut array: [i32; 3] = [0; 3];
39+
//!
40+
//! array[1] = 1;
41+
//! array[2] = 2;
1742
//!
18-
//! assert_eq!(0, array[0]);
19-
//! assert_eq!([0, 1], &array[..2]);
43+
//! assert_eq!([1, 2], &array[1..]);
2044
//!
45+
//! // This loop prints: 0 1 2
2146
//! for x in &array {
22-
//! println!("{}", x);
47+
//! print!("{} ", x);
2348
//! }
49+
//!
2450
//! ```
51+
//!
52+
//! Rust does not currently support generics over the size of an array type.
53+
//!
2554
2655
#![doc(primitive = "array")]

0 commit comments

Comments
 (0)