From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Jesung Yang" <y.j3ms.n@gmail.com>
Cc: "Jesung Yang via B4 Relay"
<devnull+y.j3ms.n.gmail.com@kernel.org>,
"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>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
nouveau@lists.freedesktop.org
Subject: Re: [PATCH v5 0/4] rust: add `TryFrom` and `Into` derive macros
Date: Wed, 01 Apr 2026 14:06:35 +0900 [thread overview]
Message-ID: <DHHK2OJ6O83V.2MZNHRQYK21EU@nvidia.com> (raw)
In-Reply-To: <DHHJCEG8BC47.2VC6GLDRRZH1B@nvidia.com>
On Wed Apr 1, 2026 at 1:32 PM JST, Alexandre Courbot wrote:
> Hi Jesung,
>
> On Fri Mar 20, 2026 at 7:04 PM JST, Jesung Yang wrote:
>> Apologies for the delay.
>
> Same. :)
>
>>
>> On Sat Feb 28, 2026 at 2:31 PM KST, Alexandre Courbot wrote:
>> [...]
>>> FWIW I have converted nova-core to use this, and this results in -200LoC
>>> delta. Obviously I like this very much. :)
>>>
>>> A few pieces of feedback for things I noticed while doing the
>>> conversion:
>>>
>>> - Very often we need to convert a type from and into the same primitive.
>>> Not having to repeat the same thing in `#[try_from(foo)]` and
>>> `#[into(foo)]` for these cases would be nice.
>>
>> I think I can add a common attribute that works for both `TryFrom` and
>> `Into`, e.g. `#[convert(foo)]`.
>>
>>> - In some rare cases, we want to convert an enum with 4 variants into
>>> e.g. a `Bounded<u8, 2>`. This can be done using a `From`
>>> implementation, and that's what the register macro expects. These
>>> cases are not covered by the current macro (they are few however).
>>
>> I think you can just do the following?:
>>
>> #[derive(Into)]
>> #[into(Bounded<u8, 2>)]
>> enum Enum {
>> A,
>> B,
>> C,
>> D,
>> }
>>
>> let a = Bounded::<u8, 2>::from(Enum::A);
>> // or let a: Bounded<u8, 2> = Enum::A.into();
>>
>> This works because `Into` actually generates the `From<Enum>`
>> implementation for `Bounded<u8, 2>`.
>
> Sorry, I said the opposite of what I meant - we want to convert a
> `Bounded<u8, 2>` into an enum with 4 variants using a `From`
> implementation.
Forgot to mention: if you want to add a `from` helper attribute, we have
a temporary implementation in nova-core that introduces a couple of
patterns you might want to follow [1].
In particular the `MAX..` arm branch to have to compiler complain if the
enum does not cover the whole range.
[1] https://lore.kernel.org/all/20260325-b4-nova-register-v4-1-bdf172f0f6ca@nvidia.com/
prev parent reply other threads:[~2026-04-01 5:06 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-29 14:32 [PATCH v5 0/4] rust: add `TryFrom` and `Into` derive macros Jesung Yang via B4 Relay
2026-01-29 14:32 ` [PATCH v5 1/4] rust: macros: add derive macro for `Into` Jesung Yang via B4 Relay
2026-01-29 16:11 ` Charalampos Mitrodimas
2026-01-30 10:03 ` Jesung Yang
2026-01-29 14:32 ` [PATCH v5 2/4] rust: macros: add derive macro for `TryFrom` Jesung Yang via B4 Relay
2026-02-04 1:39 ` Charalampos Mitrodimas
2026-02-05 21:06 ` Jesung Yang
2026-02-17 1:55 ` Alexandre Courbot
2026-02-17 2:45 ` Charalampos Mitrodimas
2026-01-29 14:32 ` [PATCH v5 3/4] rust: macros: add private doctests for `Into` derive macro Jesung Yang via B4 Relay
2026-01-29 14:32 ` [PATCH v5 4/4] rust: macros: add private doctests for `TryFrom` " Jesung Yang via B4 Relay
2026-02-03 12:48 ` [PATCH v5 0/4] rust: add `TryFrom` and `Into` derive macros shivam kalra
2026-02-28 5:31 ` Alexandre Courbot
2026-02-28 5:33 ` Alexandre Courbot
2026-03-20 10:04 ` Jesung Yang
2026-03-22 6:14 ` Jesung Yang
2026-04-01 5:19 ` Alexandre Courbot
2026-04-02 13:07 ` Jesung Yang
2026-04-02 13:36 ` Alexandre Courbot
2026-04-01 4:32 ` Alexandre Courbot
2026-04-01 5:06 ` Alexandre Courbot [this message]
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=DHHK2OJ6O83V.2MZNHRQYK21EU@nvidia.com \
--to=acourbot@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=devnull+y.j3ms.n.gmail.com@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nouveau@lists.freedesktop.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=y.j3ms.n@gmail.com \
/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