Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upas_millis function on std::time::Duration #1547
Conversation
ticki
referenced this pull request
Mar 17, 2016
Closed
Add as_millis function to std::time::Duration #1545
This comment has been minimized.
This comment has been minimized.
sfackler
reviewed
Mar 17, 2016
| # 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. |
This comment has been minimized.
This comment has been minimized.
sfackler
Mar 17, 2016
Member
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?
This comment has been minimized.
This comment has been minimized.
paezao
Mar 17, 2016
Author
Well there could be uses for both I guess but mostly the entire duration.
This comment has been minimized.
This comment has been minimized.
ticki
Mar 17, 2016
Contributor
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.
nrc
added
the
T-libs
label
Mar 17, 2016
This comment has been minimized.
This comment has been minimized.
|
The RFC should be clearer about the exact behavior of
|
This comment has been minimized.
This comment has been minimized.
main--
commented
Mar 23, 2016
|
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. |
This comment has been minimized.
This comment has been minimized.
|
cc @wycats |
This comment has been minimized.
This comment has been minimized.
|
I believe |
This comment has been minimized.
This comment has been minimized.
|
|
alexcrichton
added
the
final-comment-period
label
Apr 15, 2016
This comment has been minimized.
This comment has been minimized.
|
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! |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
trolleyman
commented
Apr 22, 2016
•
|
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. |
This comment has been minimized.
This comment has been minimized.
|
We could also call this method |
This comment has been minimized.
This comment has been minimized.
belisarius222
commented
Apr 23, 2016
|
I agree with @trolleyman that an I also like that .NET style of accessors that @main-- described. Sounds elegant and easy to work with. |
This comment has been minimized.
This comment has been minimized.
|
I disagree. Instead, it should have a overflow check when debug_assertions is on. |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
belisarius222
commented
Apr 23, 2016
|
Hmm good point. |
This comment has been minimized.
This comment has been minimized.
|
@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. :) |
This comment has been minimized.
This comment has been minimized.
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 ( |
This comment has been minimized.
This comment has been minimized.
|
@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. |
This comment has been minimized.
This comment has been minimized.
|
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! |
paezao commentedMar 17, 2016
Hello everyone!
I have an open issue about it: issue
Cheers