-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Expand documentation for the primitive type array #26923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,19 +8,48 @@ | |
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
//! The fixed-size array type (`[T; n]`). | ||
//! A fixed-size array is denoted `[T; N]` for the element type `T` and | ||
//! the compile time constant size `N`. The size should be zero or positive. | ||
//! | ||
//! Some usage examples: | ||
//! Arrays values are created either with an explicit expression that lists | ||
//! each element: `[x, y, z]` or a repeat expression: `[x; N]`. The repeat | ||
//! expression requires that the element type is `Copy`. | ||
//! | ||
//! The type `[T; N]` is `Copy` if `T: Copy`. | ||
//! | ||
//! Arrays of sizes from 0 to 32 (inclusive) implement the following traits | ||
//! if the element type allows it: | ||
//! | ||
//! - `Clone` | ||
//! - `Debug` | ||
//! - `IntoIterator` (implemented for `&[T; N]` and `&mut [T; N]`) | ||
//! - `PartialEq`, `PartialOrd`, `Ord`, `Eq` | ||
//! - `Hash` | ||
//! - `AsRef`, `AsMut` | ||
//! | ||
//! Arrays dereference to [slices (`[T]`)][slice], so their methods can be called | ||
//! on arrays. | ||
//! | ||
//! [slice]: primitive.slice.html | ||
//! | ||
//! ## Examples | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is usually |
||
//! | ||
//! ``` | ||
//! let array: [i32; 3] = [0, 1, 2]; | ||
//! let mut array: [i32; 3] = [0; 3]; | ||
//! | ||
//! array[1] = 1; | ||
//! array[2] = 2; | ||
//! | ||
//! assert_eq!(0, array[0]); | ||
//! assert_eq!([0, 1], &array[..2]); | ||
//! assert_eq!([1, 2], &array[1..]); | ||
//! | ||
//! // This loop prints: 0 1 2 | ||
//! for x in &array { | ||
//! println!("{}", x); | ||
//! print!("{} ", x); | ||
//! } | ||
//! | ||
//! ``` | ||
//! | ||
//! Rust does not currently support generics over the size of an array type. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like putting statements like these in the documentation because they will inevitably be there once we do, and not get updated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's worth it. We need to mention this. I want to invest in Rust as it is today & we don't know how many years it may take until this is no longer true. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it needs to be mentioned, as there are infinite things that Rust does not do that could be mentioned. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lots of users will realize this or ask the question when they read we have trait impls for array sizes 0 to 32, which is mentioned in this text. I think it's good to spell it out. |
||
//! | ||
|
||
#![doc(primitive = "array")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a 'must' rather than should, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but it's not the reference, so it's not so technical I thought.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
possibly, i mean we're not going all RFC 2119 or anything :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what RFC is that @steveklabnik
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently RFC 2119. I just had to google it to understand it's their text for defining what MUST, SHOULD etc mean in their standards :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, thanks; and here I went looking at Rust RFC repo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, I meant IETF RFC :(
On Sat, Jul 11, 2015 at 3:11 PM, Tshepang Lekhonkhobe <
[email protected]> wrote: