Re: [PATCH 1/2] rust: add functions and traits for lossless integer conversions

From: Miguel Ojeda

Date: Mon Jul 27 2026 - 07:12:40 EST


On Mon, Jul 27, 2026 at 12:28 PM Gary Guo <gary@xxxxxxxxxxx> wrote:
>
> I'm okay with having u32 -> usize casts and usize -> u64 casts, but having
> usize -> u32 and u64 -> usize casts like this series do is worrying as it can be
> misused from drivers that are supposed to be supporting multiple platforms or
> core subsystems.
>
> Pointer-size dependent drivers that need these casts should define them locally.

Ideally we would define it once, but nevertheless make it explicit
enough (somehow) that this makes one not build in certain configs, so
that we get no repetition and no confusion.

Something like splitting the non-portable ones into a different
trait/`mod`/method name/... so that it is very clear that it makes you
(i.e. the user) user pointer-size dependent just by e.g. `grep`ing for
it.

Cheers,
Miguel