On Thu, Oct 09, 2025 at 09:37:09PM +0900, Alexandre Courbot wrote:
> Add the BoundedInt type, which restricts the number of bits allowed to
> be used in a given integer value. This is useful to carry guarantees
> when setting bitfields.
>
> Alongside this type, many `From` and `TryFrom` implementations are
> provided to reduce friction when using with regular integer types. Proxy
> implementations of common integer traits are also provided.
>
> Signed-off-by: Alexandre Courbot <[email protected]>
> + pub const fn enlarge<const NEW_NUM_BITS: u32>(self) -> BoundedInt<T,
> NEW_NUM_BITS>
> + where
> + T: Boundable<NEW_NUM_BITS>,
> + T: Copy,
> + {
> + build_assert!(NEW_NUM_BITS >= NUM_BITS);
This assertion can be evaluated in const context.
const {
assert!(NEW_NUM_BITS >= NUM_BITS);
}
Alice