Re: [PATCH net-next v3 4/8] rust: time: Implement addition of Ktime and Delta
From: Miguel Ojeda
Date: Thu Oct 17 2024 - 12:33:49 EST
On Thu, Oct 17, 2024 at 11:31 AM FUJITA Tomonori
<fujita.tomonori@xxxxxxxxx> wrote:
>
> We could add the Rust version of add_safe method. But looks like
> ktime_add_safe() is used by only some core systems so we don't need to
> add it now?
There was some discussion in the past about this -- I wrote there a
summary of the `add` variants:
https://lore.kernel.org/rust-for-linux/CANiq72ka4UvJzb4dN12fpA1WirgDHXcvPurvc7B9t+iPUfWnew@xxxxxxxxxxxxxx/
I think this is a case where following the naming of the C side would
be worse, i.e. where it is worth not applying our usual guideline.
Calling something `_safe`/`_unsafe` like the C macros would be quite
confusing for Rust.
Personally, I would prefer that we stay consistent, which will help
when dealing with more code. That is (from the message above):
- No suffix: not supposed to wrap. So, in Rust, map it to operators.
- `_unsafe()`: wraps. So, in Rust, map it to `wrapping` methods.
- `_safe()`: saturates. So, in Rust, map it to `saturating` methods.
(assuming I read the C code correctly back then.)
And if there are any others that are Rust-unsafe, then map it to
`unchecked` methods, of course.
Cheers,
Miguel