public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Gary Guo <gary@garyguo.net>
To: Andreas Hindborg <a.hindborg@kernel.org>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rust: impl_flags: add method to return underlying integer
Date: Sat, 14 Feb 2026 09:36:58 +0000	[thread overview]
Message-ID: <5571a8bb387ca68b3f6f50d52509da52@garyguo.net> (raw)
In-Reply-To: <87zf5bsqfi.fsf@kernel.org>

On 2026-02-14 08:02, Andreas Hindborg wrote:
> Gary Guo <gary@garyguo.net> writes:
> 
>> 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@kernel.org>
>>
>> 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?
> 
> I don't see how that is better?
> 
>                 bindings::blk_mq_tag_set {
>                     ...
>                     flags: flags.into_inner(),
>                     ...
>                 }
> 
> vs
> 
>                 bindings::blk_mq_tag_set {
>                     ...
>                     flags: flags.0,
>                     ...
>                 }
> 
> 
> I would prefer the first one.

How about we expand `($inner_vis:vis $ty:ty)` to be

    $inner_vis fn into_inner(self) -> $ty {}

? This way unless you explicitly put `pub` there, users outside the module
cannot query the bit pattern.

> 
> We are going to need to be able to pass these flags into C APIs. I feel
> like adding a method to do this is the best way to go about this. We can
> call it something else if that communicates the purpose better.

I think `bitflags` crate call this `bits`, which I think is indeed
slightly better than `into_inner`.

Best,
Gary

> 
> Best regards,
> Andreas Hindborg

  reply	other threads:[~2026-02-14  9:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-12 16:02 [PATCH] rust: impl_flags: add method to return underlying integer Andreas Hindborg
2026-02-12 16:53 ` Daniel Almeida
2026-02-14  0:13 ` Gary Guo
2026-02-14  8:02   ` Andreas Hindborg
2026-02-14  9:36     ` Gary Guo [this message]
2026-02-14 11:24       ` Andreas Hindborg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5571a8bb387ca68b3f6f50d52509da52@garyguo.net \
    --to=gary@garyguo.net \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox