From: Andreas Hindborg <a.hindborg@kernel.org>
To: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"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 1/2] rust: impl_flags: add conversion functions
Date: Tue, 12 May 2026 10:05:30 +0200 [thread overview]
Message-ID: <87bjel59yt.fsf@t14s.mail-host-address-is-not-set> (raw)
In-Reply-To: <CANiq72kLDR5m8iVjDYT7doCw-z7oj2ijVK3QuA9ees7jL7zW0w@mail.gmail.com>
Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> writes:
> On Sun, Feb 15, 2026 at 9:23 PM Andreas Hindborg <a.hindborg@kernel.org> wrote:
>>
>> + impl ::core::convert::From<$flag> for $ty {
>> + #[inline]
>> + fn from(value: $flag) -> Self {
>> + // SAFETY: All `$flag` values are valid for use as `$ty`.
>> + unsafe { core::mem::transmute::<$flag, $ty>(value) }
>> + }
>> + }
>
> Why do we need the transmute instead of a cast? Did you notice a difference?
No, I did not think of using `as`. I can do that.
> Same in the other one -- why not constructing the object normally?
Will do.
> Also, you can use `Self` for `$ty` and `$flags` to make it easier to read.
Ok.
>
> In addition, I would suggest an early return with a simple `if`.
Ok.
>
> Finally, it wouldn't hurt adding a one-liner example for each at the top.
I'll add an example.
Best regards,
Andreas Hindborg
next prev parent reply other threads:[~2026-05-12 8:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-15 20:22 [PATCH 0/2] rust: impl_flags: add convenience functions Andreas Hindborg
2026-02-15 20:22 ` [PATCH 1/2] rust: impl_flags: add conversion functions Andreas Hindborg
2026-02-15 20:53 ` Miguel Ojeda
2026-05-12 8:05 ` Andreas Hindborg [this message]
2026-02-15 20:22 ` [PATCH 2/2] rust: impl_flags: add bitwise operations with the underlying type Andreas Hindborg
2026-02-27 14:20 ` [PATCH 0/2] rust: impl_flags: add convenience functions Gary Guo
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=87bjel59yt.fsf@t14s.mail-host-address-is-not-set \
--to=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=miguel.ojeda.sandonis@gmail.com \
--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