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

Alice Ryhl
2025-11-03T10:17:51Z

On Sun, Nov 02, 2025 at 11:24:42PM +0900, Alexandre Courbot wrote:
> Add the `BitInt` type, which is an integer on which the number of bits
> allowed to be used is restricted, capping its maximal value below that
> of primitive type is wraps.
>
> This is useful to e.g. enforce guarantees when working with bit fields.
>
> Alongside this type, provide many `From` and `TryFrom` implementations
> are to reduce friction when using with regular integer types. Proxy
> implementations of common integer traits are also provided.
>
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>

Reviewed-by: Alice Ryhl <aliceryhl@google.com>

> + // Statically assert that `VALUE` fits within the set number of bits.
> + const {
> + build_assert!(fits_within!(VALUE, $type, NUM_BITS));
> + }

Since it's in a const block, this can just be an assert!.

Alice