-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Docs for Duration are lacking #39949
Copy link
Copy link
Closed
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsP-mediumMedium priorityMedium priorityT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsP-mediumMedium priorityMedium priorityT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
The most common use of
Durationfor me is benchmarking, and it's always a very unpleasant experience. This is what I typically write:Output:
Duration { secs: 1, nanos: 59219906 }Wait, how much time has elapsed? That's terribly unreadable... :(
The docs for
Durationare not very helpful either. When you first see it,Durationis pretty confusing, mostly because of theas_secs/subsec_nanossplit.Then I take a look at the docs for
Instant, but the examples show how to print the seconds part only.Anyways, all I want to do is just print how much time has elapsed without squinting to connect
secsandnanostogether. Finally, I arrive at this horrible solution:Three ways of fixing this come to my mind:
Durationthat converts it to a (lossy)f64format.InstantandDurationthat demonstrate how to print the duration time in a human readable form (e.g. total seconds with precision to 3 decimals).Debugformatting forDurationand print it like this:Duration(secs.nanos: 1.059219906)(note the leading zero). Or maybe evenDuration { secs: 1, nanos: 059219906 }(again, the leading zero).What do you think?