Re: [PATCH] rust/time: Add Delta::from_nanos()

From: Onur Özkan
Date: Mon Nov 17 2025 - 05:40:25 EST


On Sun, 16 Nov 2025 12:06:41 +0100
Miguel Ojeda <miguel.ojeda.sandonis@xxxxxxxxx> wrote:

> 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`).
>

I didn't know, thanks :)

> `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.
>

Yes, that seems like a good and simple improvement.

Regards,
Onur

> Cheers,
> Miguel