[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CABm2a9cfK+HuidwQwcD0Cs_n+dvd9Y71tFn=grz1ahGpbPpurA@mail.gmail.com>
Date: Mon, 14 Jul 2025 19:16:08 -0300
From: Christian <christiansantoslima21@...il.com>
To: Alexandre Courbot <acourbot@...dia.com>
Cc: Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>, Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
Danilo Krummrich <dakr@...nel.org>, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org, ~lkcamp/patches@...ts.sr.ht,
richard120310@...il.com
Subject: Re: [PATCH v8] rust: transmute: Add methods for FromBytes trait
Hi, Alexandre. No problem, take your time.
> Let's elaborate on when it is "possible", i.e. the reference is properly
> aligned, and the size of the slice is equal to that of `T`. Let's also
> clarify that `None` is returned in other cases.
I see, thanks for a better explanation, I'll include it in the next patch.
> > + fn from_mut_bytes(bytes: &mut [u8]) -> Option<&mut Self>
>
> `from_bytes_mut` sounds like a more idiomatic name for this method.
It is done this way to match the zero copy API. [1]
> > + where
> > + Self: AsBytes;
> > +}
>
> Note that `samples/rust/rust_dma.rs` will fail to compile due to this
> change - you must make it derive `FromBytesSized` instead. There may be
> other implementors of `FromBytes` so please make sure to track and
> update them to avoid breaking the build.
In this case, if we don't include `AsBytes` the user can add padding
bytes in the slice. [2]
> nova-next also adds new implementations of `FromBytes`, and since they
> are not in mainline yet this will make it harder to adapt them... I see
> two possible solutions if we want this for the next cycle:
>
> - Take this patch into nova-next and update `FromBytes` implementations
> in lockstep,
> - Add temporary default implementations for `from_bytes` and
> `from_mut_bytes` that simply return `None` so current implementors
> keep building.
I think the first option is better considering the current state.
> I don't think this implementation takes care of arrays?
Arrays are sized types implemented in `FromBytesSized`, I believe in
this case arrays are implemented too.
[1] https://lore.kernel.org/rust-for-linux/CAGSQo03teSsTa84Mx=4SFRAfa2=irBwgXXoh5eB_Q0RoixrF6Q@mail.gmail.com/
[2] https://lore.kernel.org/rust-for-linux/D8FXFGYZTEXT.24UM4V3HZ5MWH@proton.me/
Thanks,
Christian
Powered by blists - more mailing lists