Skip to content

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

Merged
merged 1 commit into from
Jul 10, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions src/libstd/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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 :)

Copy link
Member

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

Copy link
Member Author

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 :)

Copy link
Member

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

Copy link
Member

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:

In src/libstd/array.rs
#26923 (comment):

@@ -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.

oh, thanks; and here I went looking at Rust RFC repo


Reply to this email directly or view it on GitHub
https://github.com/rust-lang/rust/pull/26923/files#r34415454.

//!
//! 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is usually # and not ##

//!
//! ```
//! 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.
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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")]