Skip to content

Commit 01e345e

Browse files
Gnurouojeda
authored andcommitted
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>
1 parent 90f3df4 commit 01e345e

File tree

2 files changed

+1059
-0
lines changed

2 files changed

+1059
-0
lines changed

rust/kernel/num.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
55
use core::ops;
66

7+
pub mod bounded;
8+
pub use bounded::*;
9+
710
/// Designates unsigned primitive types.
811
pub enum Unsigned {}
912

0 commit comments

Comments
 (0)