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

Danilo Krummrich
2025-11-04T20:22:03Z

On Tue Nov 4, 2025 at 8:30 PM CET, Yury Norov wrote:
> You switched name to BitInt, but still think about it as an object,

Note that in Rust even "real" primitives have a strong object character, they
have lots of methods, trait implementation and associated constants [1].

You can even implement your own custom traits for a primitive type in Rust.

[1] https://rust.docs.kernel.org/core/primitive.u32.html

> and that brought all the confusion in my mind. Maybe switch back to
> BoundedInt then to avoid this confusion? If you find it lengthy,
> probably LimInt or simply Lint will be better for you.

In another thread Alex proposed Bounded, because it follows the naming scheme of
other existing numeric types in Rust, e.g. NonZero [2].

[2] https://rust.docs.kernel.org/core/num/struct.NonZero.html

> Looking at how good rust macros work to implement bitfields, I thought
> that they will be able to mimic native types just as well.

I assume you mean primitive types. If so, I think there isn't too much we can't
do (e.g. literal syntax would be nice) with BitInt (or Bounded) that primitives
can do. Especially when we consider the strong object character of "real" Rust
primitives.

> With that in mind, I think that bounded integers are a bit out of
> scope of basic bit operations, and probably I'm not a right person
> to maintain them neither in Rust, nor in C.

I think it's fair to consider this kind of type as core Rust infrastructure.

Maybe a RUST [NUMERICS] entry would make sense? You could be a reviewer. :)