Skip to content
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

Closed
wants to merge 7 commits into from

Conversation

skullzzz
Copy link

reopen #20932
closes #19670

Still need to fix up tests and move them to libcollectionstest, but figured I should get comments on this implementation.

@rust-highfive
Copy link
Collaborator

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.

@Gankra
Copy link
Contributor

Gankra commented May 12, 2015

r? @gankro

@rust-highfive rust-highfive assigned Gankra and unassigned huonw May 12, 2015
use core::result::Result;

pub fn seq_fmt_debug<I: Iterator>(s: I, f: &mut Formatter) -> fmt::Result
where I::Item:fmt::Debug
Copy link
Contributor

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

Copy link
Contributor

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)

@Gankra
Copy link
Contributor

Gankra commented May 12, 2015

This is a pretty nice approach to the problem 👍

@ftxqxd
Copy link
Contributor

ftxqxd commented May 12, 2015

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 [1, 2, 3] format with Display as 1, 2, 3 or 1, 2, and 3? Or should sequences/maps not have Display formatters at all?

@Gankra
Copy link
Contributor

Gankra commented May 12, 2015

@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
https://github.com/rust-lang/rfcs/blob/master/text/0640-debug-improvements.md

@Gankra
Copy link
Contributor

Gankra commented May 12, 2015

Actually the first RFC explicitly states that Display should:

Not be implemented for generic containers like Vec or even Result<T, E>, where there is no useful, general way to tailor the output for user consumption.

@Gankra
Copy link
Contributor

Gankra commented May 12, 2015

CC @aturon

@Gankra
Copy link
Contributor

Gankra commented May 15, 2015

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?

@skullzzz
Copy link
Author

Oops, I assumed new commits would send a notification.
I think I've covered all previously pointed out issues, so yeah, ready for another pass.

@Gankra
Copy link
Contributor

Gankra commented May 18, 2015

r? @alexcrichton

It has come to my attention that current standards are ambiguous: Is Octal et al. Displayish, or Debugish? Needs decision.

@rust-highfive rust-highfive assigned alexcrichton and unassigned Gankra May 18, 2015
@Gankra Gankra added the I-needs-decision Issue: In need of a decision. label May 18, 2015
@alexcrichton alexcrichton added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label May 20, 2015
@bors
Copy link
Contributor

bors commented Jun 8, 2015

☔ The latest upstream changes (presumably #25989) made this pull request unmergeable. Please resolve the merge conflicts.

@alexcrichton
Copy link
Member

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:

  • I'd primarily recommend opening up a discuss post to gauge the interest in a feature like this along with how ambitious it should be. For example should this attempt to provide anything beyond the bare-bones formatting? If so, how would that be done?
  • You can also open up an RFC to get broader discussion about this.

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-needs-decision Issue: In need of a decision. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Formatters for collections
7 participants