Skip to content

Implementation of try_from_{nanos_u128,mins,hours,days,weeks}#153683

Open
Zorbatron wants to merge 3 commits intorust-lang:mainfrom
Zorbatron:zb/non_panicking_duration_conversion
Open

Implementation of try_from_{nanos_u128,mins,hours,days,weeks}#153683
Zorbatron wants to merge 3 commits intorust-lang:mainfrom
Zorbatron:zb/non_panicking_duration_conversion

Conversation

@Zorbatron
Copy link

@Zorbatron Zorbatron commented Mar 11, 2026

Implements the methods discussed in the related ACP. Closes rust-lang/libs-team#749.

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>;
}

ACP: rust-lang/libs-team#749
Tracking issue: #153678

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 11, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 11, 2026

r? @scottmcm

rustbot has assigned @scottmcm.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @scottmcm, libs
  • @scottmcm, libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, scottmcm

@rust-log-analyzer

This comment has been minimized.

…::error::Error` on `DurationConversionError`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ACP: Add non-panicking versions of Duration::from_{nanos_u128,mins,hours,days,weeks}

4 participants