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

From: Alexandre Courbot

Date: Fri Mar 06 2026 - 10:11:08 EST


On Fri Mar 6, 2026 at 11:32 PM JST, Alexandre Courbot wrote:
>> `MyRegArray` here is a type name that is a bitfield and not an array. `foo` returns a
>> single value and not an array. "at" here is saying that the register is at a
>> specific location and doesn't really indicate the array nature.
>>
>> This is why I insist that I would prefer an explicit location
>>
>> bar.write(REG_ARRAY.at(10), Reg::foo())
>>
>> would have no ambiguity whatsoever about user's intent.
>
> IIUC `REG_ARRAY` would be a const ZST and `at` a method returning an
> `AtArray(usize)`? I still have doubts that its generic type could be
> inferred automatically but it's worth giving it a go.
>
> If that works, then I assume fixed register writes would look like
>
> bar.write(FIXED, Reg::foo());
>
> Unless we have a specialized `write` variant for them.

So, I tried this. It seemed to work really well - but then I realized
there is a problem:

The constructor of the `AtArray` needs to check that the index is in
bounds for the register array. And to do that, it needs... the type of
the register as a generic parameter. So we would be back to repeating
the register's type in both arguments, unfortunately. :/