-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Conversation
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. |
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.
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`. |
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.
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 |
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.
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 |
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.
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`. |
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.
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 |
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.
"of a Balance
struct"
/// self | ||
/// impl Index<Side> for Balance { | ||
/// type Output = Weight; | ||
/// fn index<'a>(&'a self, index: Side) -> &'a Weight { |
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.
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 |
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.
Missing comma at the end of the line.
/// left: Weight::Pound(1.5) | ||
/// }; | ||
/// | ||
/// // in this case balance[Side::Right] is sugar for |
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.
"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 |
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.
"however" -> "However"
/// } | ||
/// |
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.
Please remove this empty line.
8347631
to
4c2ef89
Compare
Thanks for the comments, I fixed what you said and it should be fine now. |
Thanks! @bors: r+ rollup |
📌 Commit 6768edd has been approved by |
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
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