Re: [PATCH 3/6] rust: add `bitfield!` macro

From: Gary Guo

Date: Tue Jan 27 2026 - 16:11:08 EST


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.

Best,
Gary


>
> thanks,
> John Hubbard