-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Added generic example of std::ops::Add in doc comments #41612
Conversation
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
It seems like this example is being added to teach people how generic types work, which seems like a topic better suited for the book. That said, I imagine that using generic types when implementing @rust-lang/docs anyone else have opinions? |
@frewsxcv I agree, in fact the first edition of the book contains an example similar to the one in this PR. Rather than having to rummage through the book, I was thinking that something like this example should be able to be found in the API docs. What do you think? |
Well, for me it's fine. It's just the trait |
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.
Just little nits. Also, some comments in the code might help users.
src/libcore/ops.rs
Outdated
/// assert_eq!(Point { x: 1, y: 0 } + Point { x: 2, y: 3 }, | ||
/// Point { x: 3, y: 3 }); | ||
/// } | ||
/// |
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.
Extra empty line.
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.
Added the empty lines and comment regarding Output=T. Let me know if you'd like to see anything else.
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.
We now have two extra lines. :p (remove 272 and 273)
src/libcore/ops.rs
Outdated
/// Point { x: 3, y: 3 }); | ||
/// } | ||
/// | ||
/// ``` |
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.
Should be followed by an empty line.
Thinking about this some more. Maybe this example is best left in the book instead of the std lib docs. Later on I imagine something like this could go into a cookbook as well. |
I think it's a good thing to have it in multiple places. Can you just squash your commits please? Once done, I'll r+. |
Thanks! |
/// ``` | ||
/// use std::ops::Add; | ||
/// | ||
/// #[derive(Debug)] |
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.
I don't see any usage of the debug in the following code. Did you forget to remove it?
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.
The other examples derived Debug, so I followed the same path. Do you want me to remove Debug in this example and the other examples in std::Ops?
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 please (strange we kept them).
@GuillaumeGomez looks like this was updated |
@steveklabnik: I commented on my previous review. |
Looks like Debug was needed on a couple of the tests? How should we move forward? |
Put it where needed. My goal wasn't to force you to remove the |
My fault, I should have checked to see if Debug was needed. |
Ok, all good. Please squash and then I merge. |
Added blank lines around example Added comment to Add example referencing the Output type Removed whitespace from lines 272 and 273 Removed Debug derivation from Add examples Added Debug derivation
@bors r=GuillaumeGomez,frewsxcv rollup |
📌 Commit a2a9d19 has been approved by |
…meGomez,frewsxcv Added generic example of std::ops::Add in doc comments We discussed on IRC how the std::ops examples were potentially missing examples using generics. This PR adds an example to std::ops::Add that shows the use of a generic type T. I'm not sure this is ready for merge as I think the two examples now make the documentation a bit verbose, but I think it's a good starting point. I'd love to hear others thoughts on this. This is in relation to the last item in issue rust-lang#29365.
We discussed on IRC how the std::ops examples were potentially missing examples using generics. This PR adds an example to std::ops::Add that shows the use of a generic type T. I'm not sure this is ready for merge as I think the two examples now make the documentation a bit verbose, but I think it's a good starting point. I'd love to hear others thoughts on this. This is in relation to the last item in issue #29365.