-
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
Add examples to fmt precision #24662
Conversation
//! println!("Hello {1} is {2:.0$}", 5, "x", 0.01); | ||
//! println!("Hello {0} is {2:.1$}", "x", 5, 0.01); | ||
//! println!("Hello {} is {:.*}", "x", 5, 0.01); | ||
//! println!("Hello {} is {2:.*}", "x", 5, 0.01); |
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.
Perhaps have a comment above each one reading out what each one means? Something like "Hello {first argument (x)} is {second argument (0.01) with precision specified in zeroeth argument (5)}"
r=me with or without comments addressed, unless you specifically wanted Felix's r 😄 |
@steveklabnik the additions seem fine (i.e. r=me); the suggestions noted by @Manishearth also seem like good changes. Its funny (or perhaps sad); my original issue #24656 was that I could not find documentation for the actual meaning of
|
Although, reading over that text from https://github.com/rust-lang/rust/blob/master/src/libcollections/fmt.rs#L106 now, it seems like there is a little room for improvement. Namely: While that text does describe the meaning of
Update: I goofed, so I have crossed out some erroneous text from the above. Namely, the examples used |
So yes, on further reflection, while these changes are good, I think one more thing is needed: An expansion of the text at http://doc.rust-lang.org/nightly/std/fmt/index.html#precision that explains how the actual precision argument as written is interpreted.
|
I think an explicit mention of the differences between |
So here is a draft of what we might write in the new
Update: added a fifth example to the first series of Hello's to illustrate the |
(ah good doc is so hard...) |
👍 |
Right? Thanks so much :) |
@bors: r+ rollup |
📌 Commit eb5b842 has been approved by |
(Since @pnkfelix ended up writing the doc, i'll r+ it) |
Sneaking this into #24786 as well |
@bors: r+ rollup |
📌 Commit 064972c has been approved by |
Fixes rust-lang#24656 r? @pnkfelix I just added the examples, but if the wording needs expanded too, let me know what you think should be added :)
Fixes #24656
r? @pnkfelix
I just added the examples, but if the wording needs expanded too, let me know what you think should be added :)