Re: [PATCH v8 07/10] rust: io: introduce `IntoIoVal` trait and single-argument `write_val`
From: Alexandre Courbot
Date: Mon Mar 09 2026 - 22:06:08 EST
On Tue Mar 10, 2026 at 12:30 AM JST, Gary Guo wrote:
> On Mon Mar 9, 2026 at 3:14 PM GMT, Alexandre Courbot wrote:
>> Some I/O types, like fixed address registers, carry their location
>> alongside their values. For these types, the regular `Io::write` method
>> can lead into repeating the location information twice: once to provide
>> the location itself, another time to build the value.
>>
>> Add a new `Io::write_val` convenience method that takes a single
>> argument implementing `IntoIoVal`, a trait that decomposes implementors
>> into a `(location, value)` tuple. This allows write operations on fixed
>> offset registers to be done while specifying their name only once.
>>
>> Signed-off-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
>> ---
>> rust/kernel/io.rs | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> 1 file changed, 68 insertions(+)
>>
>> diff --git a/rust/kernel/io.rs b/rust/kernel/io.rs
>> index ed6fab001a39..09a0fe06f201 100644
>> --- a/rust/kernel/io.rs
>> +++ b/rust/kernel/io.rs
>> @@ -216,6 +216,22 @@ fn offset(&self) -> usize {
>> // Provide the ability to read any primitive type from a [`usize`].
>> impl_usize_ioloc!(u8, u16, u32, u64);
>>
>> +/// Trait implemented by items that contain both an I/O location and a value to assign to it.
>> +///
>> +/// Implementors can be used with [`Io::write_val`].
>> +pub trait IntoIoVal<T, L: IoLoc<T>> {
>
> Is this generics instead of associative types for some reason? If so, please
> mention it in the commit mesasge.
Associated types sound better in that situation, I don't think we can
have several implementors with different returned types for the same
value anyway.
>
>> + /// Consumes `self` and returns a `(location, value)` tuple describing a valid I/O write
>> + /// operation.
>> + fn into_io_val(self) -> (L, T);
>> +}
>> +
>> +/// `(location, value)` tuples can be used as [`IntoIoVal`]s.
>> +impl<T, L: IoLoc<T>> IntoIoVal<T, L> for (L, T) {
>
> Missing inline annotations.
Fixed, thanks! (and elsewhere in this series as well)