rust: add `Alignment` type
authorAlexandre Courbot <acourbot@nvidia.com>
Mon, 8 Sep 2025 13:25:54 +0000 (22:25 +0900)
committerMiguel Ojeda <ojeda@kernel.org>
Mon, 22 Sep 2025 21:55:41 +0000 (23:55 +0200)
commitea60cea07d8c632e8e593bb9de804abb0f6aee99
tree9cd1d9a4c85c9a6d4df4872cbab86fe7fd43c96b
parentcfe872eba9071efe4292caeceaa65d130e4d3974
rust: add `Alignment` type

Alignment operations are very common in the kernel. Since they are
always performed using a power-of-two value, enforcing this invariant
through a dedicated type leads to fewer bugs and can improve the
generated code.

Introduce the `Alignment` type, inspired by the nightly Rust type of the
same name and providing the same interface, and a new `Alignable` trait
allowing unsigned integers to be aligned up or down.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
[ Used `build_assert!`, added intra-doc link, `allow`ed
  `clippy::incompatible_msrv`, added `feature(const_option)`, capitalized
  safety comment. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/kernel/lib.rs
rust/kernel/ptr.rs [new file with mode: 0644]