rust: impl_flags: use bit helper in example
PATCH v2 1/1 rust: impl_flags: use bit helper in example
Use bit_u32() instead of open-coding shifts in the impl_flags! example. This demonstrates the checked bit helper and ensures that bit positions remain within the underlying u32 type.
---
Changes in v2:
- Use a full name for the author and Signed-off-by identities.
v1: https://lore.kernel.org/rust-for-linux/[email protected]/
rust/kernel/impl_flags.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
rust/kernel/impl_flags.rs +7 -4
@@ -19,7 +19,10 @@/// # Examples /// /// ``` -/// use kernel::impl_flags; +/// use kernel::{ +/// bits::bit_u32, +/// impl_flags, // +/// }; /// /// impl_flags!( /// /// Represents multiple permissions.
@@ -30,13 +33,13 @@/// #[derive(Debug, Clone, Copy, PartialEq, Eq)] /// pub enum Permission { /// /// Read permission. -/// Read = 1 << 0, +/// Read = bit_u32(0), /// /// /// Write permission. -/// Write = 1 << 1, +/// Write = bit_u32(1), /// /// /// Execute permission. -/// Execute = 1 << 2, +/// Execute = bit_u32(2), /// } /// ); ///
base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
Signature · 1 line
2.54.0
Quoted 9 lines · Kosumi Chan
Use
bit_u32()instead of open-coding shifts in theimpl_flags! example. This demonstrates the checked bit helper and ensures that bit positions remain within the underlying u32 type.Suggested-by Miguel Ojeda <[email protected]>Assisted-by OpenCode:openai/gpt-5.6-solSigned-off-by Kosumi Chan <[email protected]>
Looks fine, thanks.
I think I will add:
since Greg suggested the original change/idea even if not the one here.
Cheers,
Miguel
Quoted 8 lines · Kosumi Chan
Use
bit_u32()instead of open-coding shifts in theimpl_flags! example. This demonstrates the checked bit helper and ensures that bit positions remain within the underlying u32 type.Suggested-by Miguel Ojeda <[email protected]>Assisted-by OpenCode:openai/gpt-5.6-solSigned-off-by Kosumi Chan <[email protected]>
Why not. :)
Miguel Ojeda
AppliedQuoted 9 lines · Kosumi Chan
Use
bit_u32()instead of open-coding shifts in theimpl_flags! example. This demonstrates the checked bit helper and ensures that bit positions remain within the underlying u32 type.Suggested-by Miguel Ojeda <[email protected]>Assisted-by OpenCode:openai/gpt-5.6-solSigned-off-by Kosumi Chan <[email protected]>
Applied to rust-next -- thanks everyone!
Cheers,
Miguel