mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 08:04:49 +01:00
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>
This commit is contained in:
parent
90f3df4fdf
commit
01e345e82e
2 changed files with 1059 additions and 0 deletions
|
|
@ -4,6 +4,9 @@
|
|||
|
||||
use core::ops;
|
||||
|
||||
pub mod bounded;
|
||||
pub use bounded::*;
|
||||
|
||||
/// Designates unsigned primitive types.
|
||||
pub enum Unsigned {}
|
||||
|
||||
|
|
|
|||
1056
rust/kernel/num/bounded.rs
Normal file
1056
rust/kernel/num/bounded.rs
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue