Re: [PATCH] rust: impl_flags: add method to return underlying integer
From: Gary Guo
Date: Fri Feb 13 2026 - 19:13:26 EST
On 2026-02-12 16:02, Andreas Hindborg wrote:
> Add a method to return the underlying integer used for flags. This is
> useful when using the flags with C APIs.
>
> Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
I am not sure if we want to actually expose the underlying representation
for all flags. It should be something up to the caller of `impl_flags` to
decide.
Would it make sense to add visibility the wrapped raw type so that you
can do
impl_flags! {
pub struct Foo(pub u32);
...
}
to make the inner accessible?
Best,
Gary
> ---
> rust/kernel/impl_flags.rs | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/rust/kernel/impl_flags.rs b/rust/kernel/impl_flags.rs
> index e2bd7639da12e..951598497de1d 100644
> --- a/rust/kernel/impl_flags.rs
> +++ b/rust/kernel/impl_flags.rs
> @@ -267,6 +267,12 @@ pub fn contains_any(self, flags: $flags) -> bool {
> pub fn contains_all(self, flags: $flags) -> bool {
> (self.0 & flags.0) == flags.0
> }
> +
> + /// Return a copy of the inner representation of the flags.
> + #[inline]
> + pub fn into_inner(self) -> $ty {
> + self.0
> + }
> }
> };
> }
>
> ---
> base-commit: b8d687c7eeb52d0353ac27c4f71594a2e6aa365f
> change-id: 20260212-impl-flags-inner-c61974b27b18
>
> Best regards,