Skip to content

improve docs for Index and IndexMut #37438

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
Oct 31, 2016
Merged

Conversation

Cobrand
Copy link
Contributor

@Cobrand Cobrand commented Oct 27, 2016

This mainly changes the boring example of Foo/Bar of IndexMut into a better one.

Also added explanations about syntactic sugar for v[index].

Closes #36329

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @sfackler (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@sfackler
Copy link
Member

r? @steveklabnik

Copy link
Member

@GuillaumeGomez GuillaumeGomez left a comment

Choose a reason for hiding this comment

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

Excellent work! Just a few typos and should be good to go!

/// `container[index]` is actually syntactic sugar for `*container.index(index)`,
/// but only when used as an immutable value. If a mutable value is requested,
/// `IndexMut` is used instead. This allows nice things such as
/// `let value = v[index]` if `value` implements `Copy`.
Copy link
Member

Choose a reason for hiding this comment

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

Missing Copy trait url.

@@ -1879,10 +1879,15 @@ shr_assign_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
/// The `Index` trait is used to specify the functionality of indexing operations
/// like `container[index]` when used in an immutable context.
///
/// `container[index]` is actually syntactic sugar for `*container.index(index)`,
/// but only when used as an immutable value. If a mutable value is requested,
/// `IndexMut` is used instead. This allows nice things such as
Copy link
Member

Choose a reason for hiding this comment

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

Missing url for IndexMut.

///
/// `container[index]` is actually syntactic sugar for
/// `*container.index_mut(index)`, but only when used as a mutable value. If
/// an immutable value is requested, the `Index` trait is used instead. This
Copy link
Member

Choose a reason for hiding this comment

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

Missing url for Index.

/// `container[index]` is actually syntactic sugar for
/// `*container.index_mut(index)`, but only when used as a mutable value. If
/// an immutable value is requested, the `Index` trait is used instead. This
/// allows nice things such as `v[index] = value` if `value` implements `Copy`.
Copy link
Member

Choose a reason for hiding this comment

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

Missing url for Copy.

/// A trivial implementation of `IndexMut` for a type `Foo`. When `&mut Foo[2]`
/// happens, it ends up calling `index_mut`, and therefore, `main` prints
/// `Mutable indexing with 2!`.
/// A very simple implementation of a Balance struct that has two sides, where
Copy link
Member

Choose a reason for hiding this comment

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

"of a Balance struct"

/// self
/// impl Index<Side> for Balance {
/// type Output = Weight;
/// fn index<'a>(&'a self, index: Side) -> &'a Weight {
Copy link
Member

Choose a reason for hiding this comment

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

Please put an empty line before this one. It helps for the reading.

/// println!("Accessing {:?}-side of balance mutably", index);
/// match index {
/// Side::Left => &mut self.left,
/// Side::Right => &mut self.right
Copy link
Member

Choose a reason for hiding this comment

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

Missing comma at the end of the line.

/// left: Weight::Pound(1.5)
/// };
///
/// // in this case balance[Side::Right] is sugar for
Copy link
Member

Choose a reason for hiding this comment

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

"in" -> "In"

/// // balance[Side::Right], not writing it.
/// assert_eq!(balance[Side::Right],Weight::Kilogram(2.5));
///
/// // however in this case balance[Side::Left] is sugar for
Copy link
Member

Choose a reason for hiding this comment

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

"however" -> "However"

/// }
///
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this empty line.

@Cobrand Cobrand force-pushed the index_doc branch 2 times, most recently from 8347631 to 4c2ef89 Compare October 28, 2016 15:18
@Cobrand
Copy link
Contributor Author

Cobrand commented Oct 28, 2016

Thanks for the comments, I fixed what you said and it should be fine now.

@GuillaumeGomez
Copy link
Member

Thanks!

@bors: r+ rollup

@bors
Copy link
Collaborator

bors commented Oct 28, 2016

📌 Commit 6768edd has been approved by GuillaumeGomez

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Oct 31, 2016
improve docs for Index and IndexMut

This mainly changes the boring example of Foo/Bar of `IndexMut` into a better one.

Also added explanations about syntactic sugar for `v[index]`.

Closes rust-lang#36329
bors added a commit that referenced this pull request Oct 31, 2016
Rollup of 5 pull requests

- Successful merges: #37438, #37458, #37462, #37475, #37486
- Failed merges:
@bors bors merged commit 6768edd into rust-lang:master Oct 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants