Re: [PATCH v8 4/7] rust: time: Add wrapper for fsleep function

From: FUJITA Tomonori
Date: Wed Jan 22 2025 - 20:04:33 EST


On Wed, 22 Jan 2025 11:21:51 +0100
Miguel Ojeda <miguel.ojeda.sandonis@xxxxxxxxx> wrote:

> Not sure if we should say "Equivalent" given it is not exactly the
> same, but I am not a native speaker: I think it does not necessarily
> need to be exactly the same to be "equivalent", but perhaps "Similar
> to" or "Counterpart of" or something like that is better.

I'm not a native speaker either, but seems that "equivalent" can be
used as "functionally equivalent". The official Rust docs also use
"equivalent" in this sense, "Equivalent to Cʼs unsigned char type"

https://doc.rust-lang.org/std/os/raw/type.c_uchar.html

There are many places where "equivalent" is used in this sense in
rust/kernel/. Seems that only rust/kernel/block/mq.rs uses a different
word, "counterpart" in this sense.

Possibly another "good first issue" to make this expression in the
tree consistent?

>> Ah, it might work. The following doesn't work. Seems that we need to
>> add another const like MAX_DELTA_NANOS or something. No strong
>> preference but I feel the current is simpler.
>>
>> let delta = match delta.as_nanos() {
>> 0..=MAX_DELTA.as_nanos() as i32 => delta,
>> _ => MAX_DELTA,
>> };
>
> Yeah, don't worry about it too much :)
>
> [ The language may get `const { ... }` to work there (it does in
> nightly) though it wouldn't look good either. I think the `as i32`
> would not be needed. ]
>
> By the way, speaking of something related, do we want to make some of
> the methods `fn`s be `const`?

Yeah. All the from_* functions are already const. Seems that making
as_* funcations (as_nanos, etc) const too make sense.