-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Improve the docs for the write and writeln macros #40934
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @aturon (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.
This looks great! Just a few nits.
src/libcore/macros.rs
Outdated
/// This macro accepts a 'writer' (any value with a `write_fmt` method), a format string, and a | ||
/// list of arguments to format. | ||
/// This macro accepts a format string, a list of arguments, and a 'writer'. | ||
/// Arguments will be formatted according to the specified format string and the result will be |
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.
without an extra ///
in between, Markdown will merge these into one paragraph; could you add some extra ///
s here and elsewhere in the file? I think you (rightfully) wanted these to be in different paragraphs 😄
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 actually didn't (I just return after sentences out of habit so that changes to one sentence in the future don't necessarily cause the whole paragraph to be rewrapped and make the diff longer); happy to add a paragraph if you think it should be two, but it felt like a single coherent description to me (and the docs online currently are hard to read because it's mostly "single line" paragraphs, meaning there's as much whitespace in the text as text itself). Personally, I thought it was easier to read this way, but as I said, if you're sure it should be chagned I'm happy to split it out into single sentence paragraphs.
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.
It's all good! I tend to over-whitespace. If you want it in one paragraph, can you then remove the \n
s so that's more obvious? I hear you about diffs, but we haven't found it too onerous, and so don't worry about that.
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.
Done, thanks again for the review and explaining the prefered style!
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.
No problem 😁
src/libcore/macros.rs
Outdated
/// Arguments will be formatted according to the specified format string and the result will be | ||
/// passed to the writer. | ||
/// The writer may be any value with a `write_fmt` method; generally this comes from an | ||
/// implementation of either the [`std::fmt::Write`][fmt_write] or the [`std::io::Write`][io_write] |
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 know that you're adapting existing text here, but while you're here... the current style is to do
[`std::fmt::Write`]
in the text and then
[`std::fmt::Write`]: URL
for the link. Could you change all of these to be in that style? Thank you!
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.
done; thanks!
src/libcore/macros.rs
Outdated
@@ -393,30 +388,10 @@ macro_rules! write { | |||
|
|||
/// Write formatted data into a buffer, with a newline appended. | |||
/// | |||
/// On all platforms, the newline is the LINE FEED character (`\n`/`U+000A`) alone | |||
/// (no additional CARRIAGE RETURN (`\r`/`U+000D`). |
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.
It looks like we're losing this bit of docs; could we keep 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.
oops, I meant to move that into write, but it doesn't make sense there and I guess I forgot to put it back after not including it in write. Thanks!
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.
one last tiny ! to be removed and then this is good to go 👍
src/libcore/macros.rs
Outdated
/// The `write_fmt` method usually comes from an implementation of [`std::fmt::Write`][fmt_write] | ||
/// or [`std::io::Write`][io_write] traits. The term 'writer' refers to an implementation of one of | ||
/// these two traits. | ||
/// See [`std::fmt!`] for more information on the format string syntax. |
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.
an extra ! snuck in here
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.
oops, good eye; fixed. Squashing again since it's a one character change.
src/libcore/macros.rs
Outdated
/// [io_write]: ../std/io/trait.Write.html | ||
/// [fmt_result]: ../std/fmt/type.Result.html | ||
/// [io_result]: ../std/io/type.Result.html | ||
/// [`std::fmt!`]: ../std/fmt/index.html |
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.
and here
A nit on my own PR: I wonder if it would be helpful to have the statement about fmt strings (or similar):
in the |
I think that's a great idea. You're right that it's small, but little things can add up. |
Done ⤴ |
Awesome! Thanks so much! @bors: r+ rollup |
📌 Commit b03edb4 has been approved by |
…s, r=steveklabnik Improve the docs for the write and writeln macros This change reduces duplication by linking the documentation for `writeln!` to `write!`. It also restructures the `write!` documentation to read in a more logical manner (I hope; feedback would be welcome). Updates rust-lang#29329, rust-lang#29381
This change reduces duplication by linking the documentation for
writeln!
towrite!
. It also restructures thewrite!
documentationto read in a more logical manner (I hope; feedback would be welcome).
Updates #29329, #29381