Re: [PATCH 1/2] rust: sizes: add u64 variants of SZ_* constants
From: Daniel Almeida
Date: Tue Mar 10 2026 - 12:43:57 EST
> On 10 Mar 2026, at 10:51, Miguel Ojeda <miguel.ojeda.sandonis@xxxxxxxxx> wrote:
>
> 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).
>
I am not necessarily advocating one way or another, but as a further data
point: we also have a bit of this boilerplate scattered throughout Tyr.
It’d be nice to cut down on it, however it ends up being done in the end.
I do think that sizes::u64::SZ_1M does look better than what’s been proposed
in the patch, though.
> 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
>