Skip to content

Tracking Issue for try_from_{nanos_u128,mins,hours,days,weeks} methods on Duration #153678

@Zorbatron

Description

@Zorbatron

Feature gate: #![feature(non_panicking_duration_conversion)]

This is a tracking issue for the try_from_{nanos_u128,mins,hours,days,weeks} methods on Duration.

These methods will allow you to convert from a number of minutes, hours, etc, without having to having to check for overflows before calling the method.

Public API

impl Duration {
    pub const fn try_from_nanos_u128(nanos: u64) -> Result<Duration, DurationConversionError>;
    pub const fn try_from_weeks(weeks: u64) -> Result<Duration, DurationConversionError>;
    pub const fn try_from_days(days: u64) -> Result<Duration, DurationConversionError>;
    pub const fn try_from_hours(hours: u64) -> Result<Duration, DurationConversionError>;
    pub const fn try_from_mins(mins: u64) -> Result<Duration, DurationConversionError>;
}

Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

Unresolved Questions

  • TryFromFloatSecsError is still stable, but it's a type alias to DurationConversionError now. But DurationConversionError and it's fmt::Display implementation are unstable, so fmt::Display for TryFromFloatSecsError was downgraded to unstable. Should this be changed?

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

Metadata

Metadata

Assignees

Labels

C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions