Thread (31 messages) 31 messages, 6 authors, 2h ago

[PATCH RFC 03/11] rust: num: Add Bounded::USABLE_BITS

flat view
HOTtoday

From: Thomas Weißschuh <linux@weissschuh.net>
Date: 2026-10-11 12:53:09
Also in: driver-core, linux-kselftest, lkml, rust-for-linux
Subsystem: rust, rust [num], the rest · Maintainers: Miguel Ojeda, Alexandre Courbot, Linus Torvalds

Expose the types usable bits as an associated constant.

This can be used for example with static_assert!() to validate
the Bounded type against bindings constants it reflects.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 rust/kernel/num/bounded.rs | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/rust/kernel/num/bounded.rs b/rust/kernel/num/bounded.rs
index 2a2b0a4bca5e..4045e5aeb7dc 100644
--- a/rust/kernel/num/bounded.rs
+++ b/rust/kernel/num/bounded.rs
@@ -285,6 +285,9 @@ impl<T, const N: u32> Bounded<T, N>
 where
     T: Integer,
 {
+    /// Number of usable bits in this [`Bounded`] type.
+    pub const USABLE_BITS: u32 = N;
+
     /// Private constructor enforcing the type invariants.
     ///
     /// All instances of [`Bounded`] must be created through this method as it enforces most of the
-- 
2.56.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help