Rollup merge of #140882 - Dietr1ch:dev/duration_constructors_lite, r=BurntSushi

Split duration_constructors to get non-controversial constructors out

This implements #140881
This commit is contained in:
León Orell Valerian Liehr 2025-05-11 02:44:39 +02:00 committed by GitHub
commit e5835d5f76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 29 additions and 7 deletions

View File

@ -373,7 +373,7 @@ impl Duration {
/// # Examples
///
/// ```
/// #![feature(duration_constructors)]
/// #![feature(duration_constructors_lite)]
/// use std::time::Duration;
///
/// let duration = Duration::from_hours(6);
@ -381,7 +381,7 @@ impl Duration {
/// assert_eq!(6 * 60 * 60, duration.as_secs());
/// assert_eq!(0, duration.subsec_nanos());
/// ```
#[unstable(feature = "duration_constructors", issue = "120301")]
#[unstable(feature = "duration_constructors_lite", issue = "140881")]
#[must_use]
#[inline]
pub const fn from_hours(hours: u64) -> Duration {
@ -401,7 +401,7 @@ impl Duration {
/// # Examples
///
/// ```
/// #![feature(duration_constructors)]
/// #![feature(duration_constructors_lite)]
/// use std::time::Duration;
///
/// let duration = Duration::from_mins(10);
@ -409,7 +409,7 @@ impl Duration {
/// assert_eq!(10 * 60, duration.as_secs());
/// assert_eq!(0, duration.subsec_nanos());
/// ```
#[unstable(feature = "duration_constructors", issue = "120301")]
#[unstable(feature = "duration_constructors_lite", issue = "140881")]
#[must_use]
#[inline]
pub const fn from_mins(mins: u64) -> Duration {

View File

@ -24,6 +24,7 @@
#![feature(dec2flt)]
#![feature(duration_constants)]
#![feature(duration_constructors)]
#![feature(duration_constructors_lite)]
#![feature(error_generic_member_access)]
#![feature(exact_size_is_empty)]
#![feature(extend_one)]

View File

@ -46,16 +46,25 @@ fn from_weeks_overflow() {
}
#[test]
fn constructors() {
fn constructor_weeks() {
assert_eq!(Duration::from_weeks(1), Duration::from_secs(7 * 24 * 60 * 60));
assert_eq!(Duration::from_weeks(0), Duration::ZERO);
}
#[test]
fn constructor_days() {
assert_eq!(Duration::from_days(1), Duration::from_secs(86_400));
assert_eq!(Duration::from_days(0), Duration::ZERO);
}
#[test]
fn constructor_hours() {
assert_eq!(Duration::from_hours(1), Duration::from_secs(3_600));
assert_eq!(Duration::from_hours(0), Duration::ZERO);
}
#[test]
fn constructor_minutes() {
assert_eq!(Duration::from_mins(1), Duration::from_secs(60));
assert_eq!(Duration::from_mins(0), Duration::ZERO);
}

View File

@ -0,0 +1,11 @@
# `duration_constructors_lite`
The tracking issue for this feature is: [#140881]
[#140881]: https://github.com/rust-lang/rust/issues/140881
------------------------
Add the methods `from_mins`, `from_hours` to `Duration`.
For `from_days` and `from_weeks` see [`duration_constructors`](https://github.com/rust-lang/rust/issues/120301).

View File

@ -6,4 +6,5 @@ The tracking issue for this feature is: [#120301]
------------------------
Add the methods `from_mins`, `from_hours` and `from_days` to `Duration`.
Add the methods `from_days` and `from_weeks` to `Duration`.
For `from_mins` and `from_hours` see [duration-constructors-lite.md](./duration-constructors-lite.md)

View File

@ -5789,7 +5789,7 @@ The tracking issue for this feature is: [#120301]
------------------------
Add the methods `from_mins`, `from_hours` and `from_days` to `Duration`.
Add the methods `from_days` and `from_weeks` to `Duration`.
"##,
default_severity: Severity::Allow,
warn_since: None,