Skip to content

suggestion: support a const initializer #29

@sbromling

Description

@sbromling

Since Durations can be created with const fns, it would be nice if humantime::Duration could also.

It would be ideal if From and Into could be const. Since I don't believe that's possible, perhaps the following added to humantime::Duration:

    pub const fn new(std: StdDuration) -> Self {
        Self(std)
    }

Alternatively, would it be feasible to make the inner StdDuration public (i.e. pub struct Duration(pub StdDuration))? Then the const initializer wouldn't be strictly necessary, and it would give other convenient ways to access the inner duration (i.e. without using the Into or Deref+Copy impls).

I was excited to discover this crate today, because it is a pretty good fit for clap derive-style argument parsing, thanks to the addition of FromStr and Display, plus making the command line fields "unit-less" and less error-prone.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions