Re: [PATCH] rust: transmute: Add implementation for FromBytes trait

From: Miguel Ojeda
Date: Wed Oct 09 2024 - 08:32:33 EST


On Wed, Oct 9, 2024 at 3:48 AM Christian dos Santos de Lima
<christiansantoslima21@xxxxxxxxx> wrote:
>
> +pub unsafe trait FromBytes {
> + ///Converts a slice of Bytes into a Reference to Self
> + ///
> + /// # Examples
> + /// ```
> + /// pub unsafe trait FromBytes {

Apart from what Alice mentions (which is critical, since we are
looking to get into stable Rust as soon as feasible -- please see
https://rust-for-linux.com/unstable-features#usage-in-the-kernel),
please also format the code, documentation and examples appropriately
(please see other files to see how it is usually done, we mostly
follow Rust's standard library conventions).

> + unsafe {
> + let slice_ptr = slice_of_bytes.as_ptr() as *const Self;
> + &*slice_ptr
> + }

Please note that we require `// SAFETY` comments too. Missing those is
already a warning/error (depending on the kernel configuration) in
rust-next.

Thanks for the patch!

Cheers,
Miguel