[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f9f1d67f-5c89-d508-d582-528273b635db@ryhl.io>
Date: Thu, 30 Mar 2023 16:21:37 +0200
From: Alice Ryhl <alice@...l.io>
To: y86-dev@...tonmail.com
Cc: rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
patches@...ts.linux.dev, Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Wedson Almeida Filho <wedsonaf@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>
Subject: Re: [PATCH v3 05/13] rust: init: add initialization macros
On 3/30/23 00:33, y86-dev@...tonmail.com wrote:
> From: Benno Lossin <y86-dev@...tonmail.com>
>
> Add the following initializer macros:
> - `#[pin_data]` to annotate structurally pinned fields of structs,
> needed for `pin_init!` and `try_pin_init!` to select the correct
> initializer of fields.
> - `pin_init!` create a pin-initializer for a struct with the
> `Infallible` error type.
> - `try_pin_init!` create a pin-initializer for a struct with a custom
> error type (`kernel::error::Error` is the default).
> - `init!` create an in-place-initializer for a struct with the
> `Infallible` error type.
> - `try_init!` create an in-place-initializer for a struct with a custom
> error type (`kernel::error::Error` is the default).
>
> Also add their needed internal helper traits and structs.
>
> Co-developed-by: Gary Guo <gary@...yguo.net>
> Signed-off-by: Gary Guo <gary@...yguo.net>
> Signed-off-by: Benno Lossin <y86-dev@...tonmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@...gle.com>
> +/// ```rust
> +/// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)]
> +/// # use kernel::{init, pin_init, prelude::*, init::*};
> +/// # use core::pin::Pin;
> +/// # #[pin_data]
> +/// # struct Foo {
> +/// # a: usize,
> +/// # b: Bar,
> +/// # }
> +/// # #[pin_data]
> +/// # struct Bar {
> +/// # x: u32,
> +/// # }
> +///
> +/// impl Foo {
> +/// fn new() -> impl PinInit<Self> {
I would remove the empty line above `impl Foo` so that the example
doesn't start with an empty line when rendered.
> +/// # Syntax
> +///
> +/// As already mentioned in the examples above, inside of `pin_init!` a `struct` initializer with
> +/// the following modifications is expected:
> +/// - Fields that you want to initialize in-place have to use `<-` instead of `:`.
> +/// - In front of the initializer you can write `&this in` to have access to a [`NonNull<Self>`]
> +/// pointer named `this` inside of the initializer.
> +///
> +/// For instance:
> +///
> +/// ```rust
> +/// # use kernel::pin_init;
> +/// # use macros::pin_data;
> +/// # use core::{ptr::addr_of_mut, marker::PhantomPinned};
> +/// #[pin_data]
> +/// struct Buf {
> +/// ptr: *mut u8,
I'd add a comment on the `ptr` field saying "points at `buf`".
> +/// impl BigBuf {
> +/// fn new() -> impl PinInit<Self, Error> {
> +/// try_pin_init!(Self {
> +/// big: {
> +/// let zero = Box::try_new_zeroed()?;
> +/// unsafe { zero.assume_init() }
> +/// },
Is there a reason for not using `Box::init(kernel::init::zeroed())?` here?
Powered by blists - more mailing lists