Re: [PATCH v7 05/10] rust: io: add IoLoc and IoWrite types

From: John Hubbard

Date: Wed Mar 04 2026 - 14:20:34 EST


On 3/4/26 10:58 AM, Gary Guo wrote:
...
>> I see no reason why register values for different locations have to be distinct
>> in terms of value types.
>>
>> Even Nova today has quite a few registers that are just bitfields of a single
>> field that spans all bits. I think many simple driver would probably want to
>> just operate on primitives for these.
>
> I shall add that I think the fact that the registers that are *not* fields still
> gain their dedicated type in Nova driver is due to the limitation of the initial
> `register!` API design that *requires* unique types due to the `value.op(io)`
> design as opposed to `io.op(value)`.
>
> I think even these ones should eventually be replaced by just primitives
> eventually. I see no benefit of
>
> bar.write(REG.init(|x| x.with_value(value)))
>
> as opposed to just
>
> bar.write(REG, value)

All other things being equal, the second form is clearly preferable, yes.

>
> Best,
> Gary
>
>>
>> Another example is that if there're multiple registers where fields have the
>> same meaning (e.g. a device address), then a user might want to just have the
>> same type for all these values. We've already have an example of register arrays
>> that share types, and I see no reason to forbid non-array registers from also
>> sharing types.
>>
>> Forcing all registers to have different types is a design direction that I don't
>> want to take.

I also want to register (haha) a strong yet unexplainable concern about
this. Registers as types is something I've never seen attempted, it feels
strange and unnecessary, and just worries me.

thanks,
--
John Hubbard