Re: [PATCH 1/2] rust: sizes: add u64 variants of SZ_* constants
From: Miguel Ojeda
Date: Tue Mar 10 2026 - 10:37:42 EST
On Tue, Mar 10, 2026 at 3:31 AM John Hubbard <jhubbard@xxxxxxxxxx> wrote:
>
> +// CAST: every SZ_* value below fits in u64, so `as u64` is always lossless.
Nit:
// CAST: Every `SZ_*` value below fits in `u64`, so `as u64` is
always lossless.
One alternative could be something like `sizes::u64::SZ_1M`, but if
you expect to mix `usize` and `u64` often then it may not be great.
Regarding adding the constants or not, I am ambivalent. On one hand, I
see the pain of repeating it; on the other hand, adding these only
works for particular values (i.e. we still need the safe casts around
anyway for other values).
By the way, why don't we use the safe cast here? They are `const fn`,
right? i.e. that would avoid the need to justify the cast and it would
serve to double-check the cast too.
By the way (x2), if we decide to go with the constants, we may want to
use a macro to generate most of the file, which could allow us to also
have the sizes as `u32` too, in case that is useful (in 32-bit
domains?).
Thanks!
Cheers,
Miguel