Files
linux/rust/kernel
Alexandre Courbot e2d599021c rust: io: turn IoCapable into a functional trait
`IoCapable<T>` is currently used as a marker trait to signal that the
methods of the `Io` trait corresponding to `T` have been overridden by
the implementor (the default implementations triggering a build-time
error).

This goes against the DRY principle and separates the signaling of the
capability from its implementation, making it possible to forget a step
while implementing a new `Io`.

Another undesirable side-effect is that it makes the implementation of
I/O backends boilerplate-y and convoluted: currently this is done using
two levels of imbricated macros that generate unsafe code.

Fix these issues by turning `IoCapable` into a functional trait that
includes the raw implementation of the I/O access for `T` using
unsafe methods that work with an arbitrary address.

This allows us to turn the default methods of `Io` into regular methods
that check the passed offset, turn it into an address, and call into the
corresponding `IoCapable` functions, removing the need to overload them
at all.

`IoCapable` must still be implemented for all supported primitive types,
which is still done more concisely using a macro, but this macro becomes
much simpler and does not require calling into another one.

Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Acked-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://patch.msgid.link/20260206-io-v2-1-71dea20a06e6@nvidia.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
2026-03-17 20:02:09 +01:00
..
2025-10-20 04:04:23 +02:00
2025-11-05 00:05:38 +01:00
2025-11-29 10:41:09 -08:00
2025-11-04 13:25:29 +01:00
2025-07-23 02:05:58 +02:00
2025-09-06 13:27:20 +02:00
2026-02-01 22:18:24 +01:00
2026-01-30 05:47:05 +01:00
2025-08-21 16:58:07 +02:00
2025-12-28 12:43:56 +01:00
2024-11-04 16:21:44 -05:00