-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Add Duration from nanos u128 #139243
base: master
Are you sure you want to change the base?
Add Duration from nanos u128 #139243
Conversation
This comment has been minimized.
This comment has been minimized.
Add unstable attribute for `from_nanos_u128` with tracking issue rust-lang#139201 Co-authored-by: Madhav Madhusoodanan <[email protected]>
This comment has been minimized.
This comment has been minimized.
Thanks for taking this over! r? libs |
Happy to take this up. noted. |
library/core/src/time.rs
Outdated
/// creates a new Duration from the specified number of nano seconds. | ||
/// Use this function if you need to specify time greater than what can fit in u64 | ||
/// which is around 584 years and above 584.94 years to be a little more precise. |
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.
/// Creates a new Duration from the specified number of nanoseconds.
///
/// Use this function if you need to specify time greater than what can fit in u64
/// (around 584 years).
Nanoseconds is one word, summary line needs to be separate from the rest of the description, and I don't think we need to say the number of years twice.
library/core/src/time.rs
Outdated
/// ``` | ||
/// use std::time::Duration; | ||
/// let time_in_nanos = 2.pow(64); | ||
/// let duration = Duration::from_nanos_u128(time_in_nanos); | ||
/// | ||
/// ``` |
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.
Needs the #![feature(...)]
gate to work, also has a trailing newline.
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.
Hey @tgross35 thanks for the review.
will make changes and get get back.
@rustbot author |
Reminder, once the PR becomes ready for a review, use |
- add feature gate - remove trailing whitespace
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Madhav Madhusoodanan <[email protected]>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Madhav Madhusoodanan <[email protected]>
The job Click to see the possible cause of the failure (guessed by this bot)
|
What does this PR do?
This draft PR adds the
Duration::from_nanos_u128
function to handle durations that exceed the range ofu64
, allowing for time spans greater than ~584 years.Motivation
The current
Duration
API does not support creating durations from nanoseconds represented asu128
. This addition addresses that limitation.Tracking Issue
Fixes #139201
Details
Introduced
Duration::from_nanos_u128
as aconst fn
similar to other functions in the file.Ensured safety by validating the nanoseconds before using
unsafe
code.To do : complete the documentation and examples for the new function.
r? @RalfJung