Re: [PATCH v2 2/2] rust: impl_flags: add bitwise operations with the underlying type
From: Miguel Ojeda
Date: Fri Jun 05 2026 - 14:21:07 EST
On Fri, Jun 5, 2026 at 3:04 PM Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:
>
> Add bitwise or operations between the flag value enum and the underlying
> type. This is useful when manipulating flags from C API without round
> tripping into the Rust flag container type:
>
> let mut lim: bindings::queue_limits = unsafe { core::mem::zeroed() };
Can this use `zeroable` nowadays?
> if self.write_cache {
> lim.features |= request::Feature::WriteCache;
> }
>
> The above code would be needlessly verbose without this direct assignment
> option.
v2 looks better overall, but I am wondering about Gary's question in
v1 -- not sure if you saw it:
https://lore.kernel.org/rust-for-linux/DGPT710WN25X.1B9P21BE6X8P4@xxxxxxxxxxx/
The commit message shows a converted case, but is it that much
verbose? Perhaps you can point to the use case / code that made you
think about adding these `impl`s?
Thanks!
Cheers,
Miguel