Re: [PATCH v11 4/8] rust: time: Introduce Instant type

From: FUJITA Tomonori
Date: Thu Apr 03 2025 - 08:24:34 EST


On Thu, 03 Apr 2025 12:41:52 +0200
Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:

>>> As Boqun mentioned, we should make this generic over `ClockId` when the
>>> hrtimer patches land.
>>
>> Seems that I overlooked his mail. Can you give me a pointer?
>>
>> I assume that you want the Instance type to vary depending on the
>> clock source.
>
> Yea, basically it is only okay to subtract instants if they are derived
> from the same clock source. Boqun suggested here [1] before hrtimer
> patches landed I think.
>
> At any rate, now we have `kernel::time::ClockId`. It is an enum though,
> so I am not sure how to go about it in practice. But we would want
> `Instant<RealTime> - Instant<BootTime>` to give a compiler error.

Understood, thanks!

If we need a compile error for this, I don't think that the enum
works; I guess that we need a distinct type for each of RealTime,
BootTime, and so on.

Once the current patchset is merged, I'll work on that.