Re: [PATCH] rust/time: Add Delta::from_nanos()
From: Miguel Ojeda
Date: Sun Nov 16 2025 - 06:07:08 EST
On Sun, Nov 16, 2025 at 7:38 AM Onur Özkan <work@xxxxxxxxxxxxx> wrote:
>
> I wonder if it makes sense to remove all the `from_*` functions from
> `Delta` and replace them all with something like this:
>
> pub const fn from_duration(duration: Duration) -> Self {
> Self {
> nanos: duration.as_nanos(),
> }
> }
>
> What do you think?
`Delta`s can be negative and only store the nanos -- i.e. there are
many `Duration`s that do not fit in a `Delta` (`as_nanos()` above
returns `u128`).
`Delta`s are similar to `Duration` in the sense that they both store a
span of time. It seems reasonable to support similar constructors,
since they perform similar roles and we may not use `Duration`s.
Now, I agree that other types should not start getting things like
nano parameters or `from_nanos` constructors -- they should take
`Delta`s instead.
Cheers,
Miguel