Re: [PATCH v4 07/20] rust: io: implement `Mmio` as view type

From: Alexandre Courbot

Date: Tue Jun 16 2026 - 10:28:25 EST


On Tue Jun 16, 2026 at 8:12 PM JST, Gary Guo wrote:
> On Tue Jun 16, 2026 at 1:18 AM BST, Alexandre Courbot wrote:
>> On Tue Jun 16, 2026 at 12:13 AM JST, Gary Guo wrote:
>>>> Is there a reason for not just declaring `RelaxedMmio` as
>>>>
>>>> #[repr(transparent)]
>>>> pub struct RelaxedMmio<'a, T: ?Sized>(Mmio<'a, T>);
>>>>
>>>> similarly to what the original code did with `MmioOwned`?
>>>>
>>>> I tried locally and could build. This avoids declaring `Mmio` and
>>>> `RelaxedMmio` as basically identical types, and lets us remove the
>>>> explicit `Send` and `Sync` implementations. IIUC you can also reduce or
>>>> even remove the invariant section as it is enforced by `Mmio`.
>>>
>>> This is what I did originally, but this would cause duplication for
>>> RelaxedMmioBackend, as now you have to do
>>>
>>> unsafe { bindings::$read_fn(view.0.ptr.cast_const().cast()) }
>>>
>>> and the `.0` causes the macro not being shared with MmioBackend.
>>
>> Since `MmioBackend` and `RelaxedMmioBackend` both implement `IoBackend`,
>> I think using `IoBackend::as_ptr` in the macro should let you avoid the
>> duplication?
>
> Good point. Are you okay with the following diff?

Yes, that looks great, thanks!

Reviewed-by: Alexandre Courbot <acourbot@xxxxxxxxxx>