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

From: Alice Ryhl
Date: Mon Nov 03 2025 - 05:19:15 EST


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@xxxxxxxxxx>

Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>

> + // 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