-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-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.
Description
I often find myself needing this extension to std
's Duration
, why isn't something like this part of std
? :)
pub trait DurationExt {
fn as_msecs(&self) -> u64;
fn as_microsecs(&self) -> u64;
fn as_nanosecs(&self) -> u64;
}
impl DurationExt for Duration {
fn as_msecs(&self) -> u64 {
self.as_secs() * 1_000 + (self.subsec_nanos() as f64 / 1_000_000.0).round() as u64
}
fn as_microsecs(&self) -> u64 {
self.as_secs() * 1_000_000 + (self.subsec_nanos() as f64 / 1_000.0).round() as u64
}
fn as_nanosecs(&self) -> u64 {
self.as_secs() * 1_000_000_000 + self.subsec_nanos() as u64
}
}
Metadata
Metadata
Assignees
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-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.