-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking Issue for Duration::{zero, is_zero}
(#![feature(duration_zero)]
)
#73544
Comments
This comment has been minimized.
This comment has been minimized.
Duration::{zero, is_zero}
(#![feature(duration_zero)]
)
This comment has been minimized.
This comment has been minimized.
Are there plans for stabilization? I had these two traits in my code for over a year, and they now show the "unstable_name_collisions" lint every build, everywhere they're used - /// Extensions for `Duration`
pub trait DurationExt : Copy {
/// Returns true if self is equivalent to zero
fn is_zero(self) -> bool;
/// Get a zero duration
fn zero() -> Duration {
Duration::new(0, 0)
}
}
impl DurationExt for Duration {
#[inline]
fn is_zero(self) -> bool {
self.as_secs() == 0 && self.subsec_nanos() == 0
}
} |
My guess is that these can probably be stabilized as-is? |
As the top comments says, the only open question is basically whether we want the associated const // Do we want this?
let d = Duration::zero();
if d.is_zero() { ... }
// Or rather this?
let d = Duration::ZERO;
if d == Duration::ZERO { ... } There are certainly some uses of associated consts in std already:
I think both of those two solutions (or any mix of those) would be fine. I don't think anyone would consider either of those a "bad API". So if you think that either one of those should be stabilized, go ahead and either open a PR that adds the const |
I was thinking about the pros and cons, and I'm really divided, though leaning slightly towards ZERO
Regardless, |
My preference is for the constant. Places that need a function can easily be given |
As of #78216, Nightly Rust moves to the constant for a variety of reasons stated here, in addition to the fact that a const does not require a const evaluation context in order to be used in places where consts but not dynamic values are accepted... this matters a lot for |
Are there any open questions remaining, or does this just need a stabilization PR now? |
@rfcbot merge |
Team member @m-ou-se has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
Well, I suppose it is a final comment period: I do not particularly feel that use std::time::Duration;
use std::cmp::PartialEq;
use fun_library::some_duration;
fn main() {
let d = some_duration();
if d.eq(&Duration::ZERO) {
println!("what could be less than an instant?");
}
} But neither am I strongly against if it is felt that there is something different about Duration that justifies such. That said, every additional line in documentation makes it harder to find other lines in documentation, so I still feel it should justify itself. |
@workingjubilee I guess I don't really see |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. The RFC will be merged soon. |
That seems fair, then, if the precedent is not considered to hold in either direction. |
Without |
Stabilize duration_zero. FCP here: rust-lang#73544 (comment)
Stabilize duration_zero. FCP here: rust-lang#73544 (comment)
Stabilized in #84084. |
This is a tracking issue for
Duration::{ZERO, is_zero}
(#![feature(duration_zero)]
). Proposed in RFC 2814 which got closed just because such a small change does not require an RFC. Proposed again and implemented in #72790.Steps
Unresolved questions:
ZERO
? yes. donezero
function? yes,zero()
is removed.The text was updated successfully, but these errors were encountered: