Re: [PATCH 1/2] rust: add BitInt integer wrapping type

Alexandre Courbot
2025-11-03T13:57:36Z

On Mon Nov 3, 2025 at 10:42 PM JST, Alexandre Courbot wrote:
<snip>
> After comparing this implementation with C's `_BitInt`, I have also come
> to a more fundamental divergence between the two.
>
> The C `_BitInt` is used to express numbers with an arbitrary number of
> bits - which could be less than a primitive type, but also *more* - for
> instance a `_BitInt(4094)` is a valid thing!
>
> Which is really cool, but also not something we need or want in the
> kernel. Our purposes here is strictly to limit the width of existing
> primitive types to provide extra guarantees about the code. And even if
> we wanted to mimic the C `_BitInt`, we simply couldn't without compiler
> support as literal values larger than a primitive type cannot even be
> expressed.
>
> So although I liked the `BitInt` name, that makes it quite a bit
> misleading for our type as users could think that they will have an
> equivalent to the C namesake, while the purpose and use is different.
>
> The original `BoundedInt` name was a more accurate fit IMHO, but I hope
> we can find something shorter.

Actually - the core library names similar wrapping types `NonZero` or
`Wrapping` - not `NonZeroInt` or `WrappingInt`. So this type could just
be called `Bounded`, as its generic parameter makes it clear what it
sets the bounds of anyway.