-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
as_millis function on std::time::Duration #1547
Conversation
# Detailed design | ||
[design]: #detailed-design | ||
|
||
Add a `as_millis` function on `std::time::Duration` that divides `self.nanos` by `NANOS_PER_MILLI` and returns it. |
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.
Is this actually how this should behave? Will users typically only want the subsecond portion of the duration in milliseconds or the entire duration in milliseconds?
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.
Well there could be uses for both I guess but mostly the entire duration.
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.
I think the usecase for the whole duration would be the main one. Another RFC should add a way to construct a subsec duration from the duration.
The RFC should be clearer about the exact behavior of
|
A serious drawback of the current design is that it doesn't match the behavior of One example to look at is .NET's Another possible approach would be to offer incredible flexibility by extending the existing API ( In any case, it may be beneficial to move these utility functions away from the basic Another thing to consider is that all of this could be developed as a library and merged into std once it's mature enough. |
cc @wycats |
I believe |
🔔 This RFC is now entering its week-long final comment period 🔔 |
I personally find it somewhat odd that we have a
I feel that there are a few too many open questions at this time to move on this API just yet, but @main--'s comment about .NET seems like a good place to draw inspiration from! |
I agree with the questions others have raised about the semantics here -- the RFC needs much more detail, and in particular needs to address the overflow concern directly. I don't think this RFC is ready for acceptance as-is, but I do think that we should add this functionality in some form eventually. (As a sidenote, I think we may want to consider renaming |
I think that the option of returning u64 and panicing on overflow is fine. This is because once you do the calculations I feel like u64 is more than large enough for normal durations. |
We could also call this method |
I agree with @trolleyman that an I also like that .NET style of accessors that @main-- described. Sounds elegant and easy to work with. |
I disagree. Instead, it should have a overflow check when debug_assertions is on. |
I think @trolleyman's case actually supports the position of not having a overflow check, since it is extremely unlikely, and will pratically never happen. |
Hmm good point. |
@belisarius222 @ticki I can see one motivation for not having an overflow check: Performance. As I don't think performance is of utmost relevance here (see e.g. the If we want to omit the overflow check, we need a motivation. :) |
Overflow is pratically unreachable in this case, and will likely only be found in testing scenarios. I believe that the best solution would be having overflow checks enabled in debug mode ( |
@ticki I don't think we can make a consistency argument here. Rust only tries to do unexpected things if it matters for performance, it's not that it makes sense for this method to wrap around. |
The libs team discussed this RFC in triage today and the decision was to close. As written we decided that we probably don't want a function called In the meantime @sfackler has started developing a Thanks again though for the RFC @paezao! |
Hello everyone!
I have an open issue about it: issue
Cheers