Re: [PATCH v8 4/7] rust: time: Add wrapper for fsleep function
From: FUJITA Tomonori
Date: Wed Jan 22 2025 - 19:12:44 EST
On Wed, 22 Jan 2025 18:06:58 +0100
Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
>> > >> + let duration = if delta > MAX_DURATION || delta.is_negative() {
>> > >> + // TODO: add WARN_ONCE() when it's supported.
>> > >
>> > > Ditto (also "Add").
>> >
>> > Oops, I'll fix.
>> >
>> > > By the way, can this be written differently maybe? e.g. using a range
>> > > since it is `const`?
>> >
>> > A range can be used for a custom type?
>>
>> Yes, you can say `!(Delta::ZERO..MAX_DURATION).contains(&delta)`.
>> (You'll need to add `Delta::ZERO`).
>
> It would need to use ..= instead of .. to match the current check.
Neat, it works as follows.
let delta = if (Delta::ZERO..=MAX_DELTA).contains(&delta) {
delta
} else {
MAX_DELTA
};