public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Gary Guo" <gary@garyguo.net>
Cc: "John Hubbard" <jhubbard@nvidia.com>,
	"Yury Norov" <ynorov@nvidia.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"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>,
	"Yury Norov" <yury.norov@gmail.com>,
	"Alistair Popple" <apopple@nvidia.com>,
	"Joel Fernandes" <joelagnelf@nvidia.com>,
	"Timur Tabi" <ttabi@nvidia.com>, "Edwin Peer" <epeer@nvidia.com>,
	"Eliot Courtney" <ecourtney@nvidia.com>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Dirk Behme" <dirk.behme@de.bosch.com>,
	"Steven Price" <steven.price@arm.com>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/6] rust: add `bitfield!` macro
Date: Wed, 28 Jan 2026 10:28:54 +0900	[thread overview]
Message-ID: <DFZTZP38P352.170EYBILZUR92@nvidia.com> (raw)
In-Reply-To: <DFZOHYP9I47G.14DDKPXUOU4V0@garyguo.net>

On Wed Jan 28, 2026 at 6:10 AM JST, Gary Guo wrote:
> On Tue Jan 27, 2026 at 9:03 PM GMT, John Hubbard wrote:
>> On 1/27/26 1:57 AM, Alexandre Courbot wrote:
>>> On Tue Jan 27, 2026 at 11:55 AM JST, Yury Norov wrote:
>>> <snip>
>>> 
>>> So while we cannot achieve exactly the short syntax above (which has its
>>> drawbacks as well, such as the inability to operate in const context),
>>> we can introduce a new setter than works with a const argument and
>>> spares us the need to invoke `Bounded::new` ourselves:
>>> 
>>>      let color = Rgb::default().
>>>              .with_red::<0x10>()
>>>              .with_green::<0x1f>()
>>>              .with_blue::<0x18>()
>>
>> Are we sure that .with_red is a better name than, say, .set_red()?
>>
>> "with" is not so easy to remember, because it is a bit
>> surprising and different, for setting a value.
>>
>> "with" feels like a function call or closure: "sort with
>> qsort", for example. But here we are setting a color
>> component.
>
> `set_foo` implies that the value is mutated in place (and takes `&mut self`).
> `with_foo` implies that value is returned with the specific thing changed. For
> example, `pointer::with_addr`, `Path::with_extension`.
>
> Given the signature in the API I would agree with Yury that `with_` is better.

Indeed, given the signature of the method `with_` is definitely more
idiomatic. But that is also true for the non-const setter, and they
unfortunately cannot share the same name.

Alternative names I can think of for the non-const / const setters:

- `with_foo`/`with_foo_const`, but that's a bit verbose,
- `with_foo`/`const_foo`, but that's not idiomatic either,
- `with_foo_val`/`with_foo`, but that increases the risk of name
  clashes.

... so unless there are better proposals I guess the
`set_foo`/`with_foo` is at least practical, if a bit unconventional.

  parent reply	other threads:[~2026-01-28  1:29 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-20  6:17 [PATCH 0/6] rust: add `bitfield!` and `register!` macros Alexandre Courbot
2026-01-20  6:17 ` [PATCH 1/6] rust: num: add `shr` and `shl` methods to `Bounded` Alexandre Courbot
2026-01-20  8:44   ` Alice Ryhl
2026-01-20 12:53     ` Alexandre Courbot
2026-01-20 16:12   ` kernel test robot
2026-01-21  8:15   ` Yury Norov
2026-01-21 10:10     ` Alice Ryhl
2026-01-20  6:17 ` [PATCH 2/6] rust: num: add `as_bool` method to `Bounded<_, 1>` Alexandre Courbot
2026-01-20  8:45   ` Alice Ryhl
2026-01-20  6:17 ` [PATCH 3/6] rust: add `bitfield!` macro Alexandre Courbot
2026-01-20 11:45   ` Dirk Behme
2026-01-20 12:37     ` Miguel Ojeda
2026-01-20 12:47       ` Dirk Behme
2026-01-20 13:08         ` Miguel Ojeda
2026-01-20 13:20           ` Alexandre Courbot
2026-01-20 21:02             ` Miguel Ojeda
2026-01-20 12:51     ` Alexandre Courbot
2026-01-21  9:16   ` Yury Norov
2026-01-26 13:35     ` Alexandre Courbot
2026-01-27  2:55       ` Yury Norov
2026-01-27  3:25         ` Joel Fernandes
2026-01-27  4:49           ` Yury Norov
2026-01-27 10:41             ` Alexandre Courbot
2026-01-27 10:55               ` Miguel Ojeda
2026-01-28  5:27               ` Yury Norov
2026-01-28 14:12                 ` Alexandre Courbot
2026-01-28 18:05                   ` Yury Norov
2026-01-29 13:40                     ` Alexandre Courbot
2026-01-29 15:12                       ` Miguel Ojeda
2026-01-27 11:00             ` Joel Fernandes
2026-01-27 15:02           ` Gary Guo
2026-01-28  1:23             ` Alexandre Courbot
2026-01-28  4:33               ` Yury Norov
2026-01-28 14:02                 ` Alexandre Courbot
2026-01-28 18:12                   ` Yury Norov
2026-01-27  9:57         ` Alexandre Courbot
2026-01-27 21:03           ` John Hubbard
2026-01-27 21:10             ` Gary Guo
2026-01-27 21:22               ` John Hubbard
2026-01-28  1:28               ` Alexandre Courbot [this message]
2026-01-28  1:41                 ` John Hubbard
2026-01-20  6:17 ` [PATCH 4/6] rust: bitfield: Add KUNIT tests for bitfield Alexandre Courbot
2026-01-20  6:17 ` [PATCH 5/6] rust: io: add `register!` macro Alexandre Courbot
2026-01-20  6:17 ` [PATCH FOR REFERENCE 6/6] gpu: nova-core: use the kernel `register!` and `bitfield!` macros Alexandre Courbot
2026-01-20 13:14 ` [PATCH 0/6] rust: add `bitfield!` and `register!` macros Miguel Ojeda
2026-01-20 13:38   ` Danilo Krummrich
2026-01-20 13:50     ` Miguel Ojeda
2026-01-20 14:18       ` Danilo Krummrich
2026-01-20 14:57         ` Miguel Ojeda
2026-01-20 15:27           ` Danilo Krummrich
2026-01-20 15:48             ` Miguel Ojeda
2026-01-20 20:01               ` Danilo Krummrich
2026-01-20 20:31                 ` Miguel Ojeda
2026-01-21  5:57                   ` Yury Norov
2026-01-21  6:55                     ` Alexandre Courbot
2026-01-26 14:03                     ` Joel Fernandes

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=DFZTZP38P352.170EYBILZUR92@nvidia.com \
    --to=acourbot@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=dirk.behme@de.bosch.com \
    --cc=ecourtney@nvidia.com \
    --cc=epeer@nvidia.com \
    --cc=gary@garyguo.net \
    --cc=jhubbard@nvidia.com \
    --cc=joelagnelf@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=steven.price@arm.com \
    --cc=tmgross@umich.edu \
    --cc=ttabi@nvidia.com \
    --cc=ynorov@nvidia.com \
    --cc=yury.norov@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