On Wed Sep 2, 2026 at 10:16 AM BST, Eliot Courtney wrote:
> Currently, using NonZero/Bounded constants is quite verbose. It's
> unfortunate because it disincentivizes using it in interface boundaries.
> Introduce a macro to make it nicer to use. The macro `cv!` (for constant
> value) takes a const integer expression and widens it to i128 (at build
> time only) before passing it as a const generic value to a new trait
> `FromConst`. The value is then converted and appears in the
> associated constant `FromConst::VALUE`. The trait is implemented by
> NonZero, Bounded, and Alignment and lets values of each be constructed
> from constants without a verbose turbofish syntax.
> For example, `const { NonZero::new(1).unwrap() }` can be written as
> `cv!(1)`.
>
> Suggested-by: Gary Guo <[email protected]>
> Signed-off-by: Eliot Courtney <[email protected]>Reviewed-by: Gary Guo <[email protected]> > --- > rust/kernel/num.rs | 138 > +++++++++++++++++++++++++++++++++++++++++++++ > rust/kernel/num/bounded.rs | 19 +++++++ > rust/kernel/ptr.rs | 14 +++++ > 3 files changed, 171 insertions(+) > > diff --git a/rust/kernel/num.rs b/rust/kernel/num.rs > index dbe848e30efe..9435459376a4 100644 > --- a/rust/kernel/num.rs > +++ b/rust/kernel/num.rs > @@ -2,6 +2,7 @@ > > //! Additional numerical features for the kernel. > > +use crate::const_assert; > use core::ops; nit: commonly Rust code uses core/std -> dependency -> crate/super import order (known as std/extern/crate order), so this would be use core::ops; use crate::const_assert; under that order. But I don't think we require that (so no need to resend). Best, Gary
