]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
rust: num: add Bounded integer wrapping type
authorAlexandre Courbot <acourbot@nvidia.com>
Sat, 8 Nov 2025 02:23:48 +0000 (11:23 +0900)
committerMiguel Ojeda <ojeda@kernel.org>
Tue, 18 Nov 2025 23:22:24 +0000 (00:22 +0100)
commit01e345e82ec3a5a7edeb9fa0dcb7fd4b0e5c534e
tree99385318f9e308381ef2a313fbc452a455b88e71
parent90f3df4fdfb682e2394ee3f97dfe91a402d5c46a
rust: num: add Bounded integer wrapping type

Add the `Bounded` integer wrapper type, which restricts the number of
bits allowed to represent of value.

This is useful to e.g. enforce guarantees when working with bitfields
that have an arbitrary number of bits.

Alongside this type, provide many `From` and `TryFrom` implementations
are to reduce friction when using with regular integer types. Proxy
implementations of common integer operations are also provided.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://patch.msgid.link/20251108-bounded_ints-v4-2-c9342ac7ebd1@nvidia.com
[ Added intra-doc link. Fixed a few other nits. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/kernel/num.rs
rust/kernel/num/bounded.rs [new file with mode: 0644]