-
Notifications
You must be signed in to change notification settings - Fork 13.3k
std: add Duration::as_millis #28404
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
std: add Duration::as_millis #28404
Conversation
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
/// Returns the number of whole milliseconds represented by this duration. | ||
#[unstable(feature = "duration_as_millis", reason = "newly added")] | ||
pub fn as_millis(&self) -> u64 { | ||
self.secs * MILLIS_PER_SEC + ((self.nanos / NANOS_PER_MILLI) as u64) |
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.
This can overflow, so should probably return an Option instead.
5e4ea3e
to
600dc8e
Compare
@sfackler updated to use Option |
The RFC for
As a result, I think that accessor methods like this may wish to go through an RFC. For example I would have questions along the lines of:
|
@alexcrichton This is motivated by balancing the accessors with the constructors: there exists But I definitely can see how the color of this shed could be rainbow, and I can write a function to do the same thing for my needs. |
I understand the motivation, but I don't personally think that it's strong enough to bypass an RFC when the original RFC explicitly avoided this. |
Following "do whatever is easiest", this was about the same amount of work to implement vs write up an RFC.
Motivation: there already exists a
Duration::from_millis
function, but no mirrorDuration::as_millis
. Milliseconds are commonly desired in programming, and the lack ofas_millis
feels unbalanced.