-
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
implement fmt traits for collections #25319
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @huonw (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. 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 CONTRIBUTING.md for more information. |
r? @gankro |
use core::result::Result; | ||
|
||
pub fn seq_fmt_debug<I: Iterator>(s: I, f: &mut Formatter) -> fmt::Result | ||
where I::Item:fmt::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.
Missing a space after colon
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 is pretty much everywhere in this PR)
This is a pretty nice approach to the problem 👍 |
I feel like this would require an RFC—there are alternative approaches to this (e.g., adding formatting syntax for explicitly applying a formatter to the items in an iterable). Also, the precise details aren’t easy to settle on; e.g., should |
@P1start There have been two RFCs, both of which provide guidance on collection formatting: https://github.com/rust-lang/rfcs/blob/master/text/0565-show-string-guidelines.md |
Actually the first RFC explicitly states that Display should:
|
CC @aturon |
Oh! Just saw you added commits (Github doesn't notify anyone when that happens). Are you still working on stuff or are you ready for another pass? |
Oops, I assumed new commits would send a notification. |
It has come to my attention that current standards are ambiguous: Is Octal et al. Displayish, or Debugish? Needs decision. |
☔ The latest upstream changes (presumably #25989) made this pull request unmergeable. Please resolve the merge conflicts. |
Thanks again for the PR @skullzzz! For now, though, there is enough consensus to merge this. There are remaining concerns about how ambitious collections should be in their formatting (especially when it comes to the various flags formatters have). It's also possible to add these formattings as adaptors if necessary, or just writing a helper method. If you're interested in pursuing this, though, I'd recommend one of two courses of action:
One of the unfortunate parts about stability today is that any trait implementation is insta-stable, so there's a bit higher of a bar for entry for trait impls than new structures (as we can't introduce this as stable functionality). |
reopen #20932
closes #19670
Still need to fix up tests and move them to libcollectionstest, but figured I should get comments on this implementation.