Skip to content

Missing trait Debug for std::time::Instant #31866

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

Closed
vi opened this issue Feb 24, 2016 · 5 comments
Closed

Missing trait Debug for std::time::Instant #31866

vi opened this issue Feb 24, 2016 · 5 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. P-low Low priority T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@vi
Copy link
Contributor

vi commented Feb 24, 2016

Although

There is no method to get "the number of seconds" from an instant.

, I think Debug may leak internal representation which can include those number of seconds (or some other increasing number).

@durka
Copy link
Contributor

durka commented Feb 24, 2016

Debug doesn't have to be derived. println!("{:?}", Instant::now()) could simply print "Instant".

@vi
Copy link
Contributor Author

vi commented Feb 24, 2016

But it's not really useful for debugging the code that compares/offsets them a lot.

@steveklabnik steveklabnik added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed A-libs labels Mar 24, 2017
@Mark-Simulacrum
Copy link
Member

I believe this issue is about the Debug implementation for Instant exposing internal API details, but I don't necessarily see that as a bad thing. I think it's somewhat expected that while Debug may print information, the actual output should not be relied upon (i.e., parsing it would not be acceptable). I'm nominating for the libs team since this general question is interesting for the API guidelines discussion: Can/should Debug impls expose internals in order to aid debugging?

@alexcrichton
Copy link
Member

We discussed this at trigae today and concluded:

  • We should implement Debug no matter what
  • Exposing internal details is fine here
  • Exposing more internals (calculated at runtime) would also be ok to get a better debug representation. Sort of like how TcpStream prints out the peer/local addrs.

Patches are of course welcome to help implement this!

@alexcrichton alexcrichton added P-low Low priority and removed I-nominated labels Jun 20, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 24, 2017
@dtolnay
Copy link
Member

dtolnay commented Nov 17, 2017

I believe this impl has existed since the very beginning of std::time::Instant -- #29894 contains impl Debug for Instant. This code is stable as of Rust 1.8.0:

fn main() {
    println!("{:?}", std::time::Instant::now());
}

The output is Instant { tv_sec: 17586727, tv_nsec: 739140298 } which seems to align with the discussion here.

@dtolnay dtolnay closed this as completed Nov 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. P-low Low priority T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants