Re: [PATCH v9] rust: transmute: Add methods for FromBytes trait

From: Alexandre Courbot
Date: Mon Aug 18 2025 - 07:32:20 EST


On Wed Aug 13, 2025 at 3:00 AM JST, Christian wrote:
> Hi, Alexandre.
>
>> I mentioned it on v8 [1] and v7 [2], but the tests that break due to
>> this change need to be updated by this patch as well. This includes:
>>
>> * The doctests in `rust/kernel/dma.rs`,
>> * The `samples/rust/rust_dma.rs` sample,
>> * The example for `FromBytes` introduced by this patch which uses `?` without
>> defining a function.
>
> Sorry for my inattention, I'll fix this in the next version.

Ah, as it turns out you might not need to.

We discussed this patch a bit during the DRM sync, and the consensus was
that it would probably be better to keep things a bit simpler for the
first version. The `FromBytesSized` trait in particular was not very
popular; a better long-term way to provide implementations for
`FromBytes` would be to use a derive macro, but that's out of scope for
now.

Instead, we agreed that the following would make a good first version:

- Make the `FromBytes` trait depend on `Sized`,
- Provide default implementations for `from_bytes` and `from_bytes_mut`
directly in the `FromBytes` trait,
- No implementation for slices for now,
- Consequently, no user code will break due to the addition of the
methods, which is a big plus.

The simpler version that would result from this covers all the immediate
use-cases and would be easier to merge, which will give us some time to
think about how to handle the non-sized use cases (probably via a derive
macro).

Do you think you could write the next version along these lines?

I feel like I misdirected you with the `FromBytesSized` trait, so please
accept my apologies for that.