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 Display for Duration. #29146

Closed
wants to merge 1 commit into from

Conversation

SimonSapin
Copy link
Contributor

… or was there a reason not to do it?

r? @alexcrichton

@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 @alexcrichton (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 the contribution instructions for more information.

@SimonSapin
Copy link
Contributor Author

Oh, I just found #25481. This may need to be more involved than I thought (rounding vs truncating, the meaning of width/padding, …) but I’m less convinced about using a different unit based on the range of value.

CC @kballard

@lilyball
Copy link
Contributor

@SimonSapin If you don't use a different unit, then Display will be useless for most uses, because it will only be appropriate for durations of a scale that makes sense with the unit you chose.

@alexcrichton
Copy link
Member

I do think this type should implement Display, but as #25481 has shown I think it's a pretty tricky situation about what it should actually be displaying. We may want to figure out what format should be displayed before pushing forward with an implementation.

For example, if I have a 3 nanosecond duration it seems like the "most readable" representation would be along the lines of 3ns rather than 0.000000003 as I believe this would print.

@alexcrichton alexcrichton added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Oct 21, 2015
@alexcrichton
Copy link
Member

The libs team discussed this during triage yesterday, and the conclusion was that we probably don't actually want a Display implementation on Duration. Following the guidelines for Display an interesting point about durations is that there seems to be no "one true way" to display them that is both not lossy and useful. As a result, it's likely that we may want to provide adapters which themselves implement Display to get different methods of formatting a duration, but we probably don't want a Display implementation itself on the type.

As a result I'm going to close this for now, but we also decided we'd be fine with an unstable method returning a display-able adapter, so feel free to open a PR with that!

@alexcrichton
Copy link
Member

Ah and another point brought up by @brson is that once you start dealing with time + printing the question of locales can come into play, so we either need to have a story around that or ensure that we're stepping around the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

4 participants