Re: [PATCH v2] rust: Implement the smart pointer `InPlaceInit` for `Arc`
From: Alice Ryhl
Date: Mon Jul 22 2024 - 05:09:29 EST
On Fri, Jul 19, 2024 at 9:22 PM Alex Mantel <alexmantel93@xxxxxxxxxxx> wrote:
>
> For pinned and unpinned initialization of structs, a trait named
> `InPlaceInit` exists for uniform access. `Arc` did not implement
> `InPlaceInit` yet, although the functions already existed. The main
> reason for that, was that the trait itself returned a `Pin<Self>`. The
> `Arc` implementation of the kernel is already implicitly pinned.
>
> To enable `Arc` to implement `InPlaceInit` and to have uniform access,
> for in-place and pinned in-place initialization, an associated type is
> introduced for `InPlaceInit`. The new implementation of `InPlaceInit`
> for `Arc` sets `Arc` as the associated type. Older implementations use
> an explicit `Pin<T>` as the associated type. The implemented methods for
> `Arc` are mostly moved from a direct implementation on `Arc`. There
> should be no user impact. The implementation for `ListArc` is omitted,
> because it is not merged yet.
>
> Link: https://github.com/Rust-for-Linux/linux/issues/1079
> Signed-off-by: Alex Mantel <alexmantel93@xxxxxxxxxxx>
> [...]
> /// Smart pointer that can initialize memory in-place.
> pub trait InPlaceInit<T>: Sized {
> + /// A type might be pinned implicitly. An addtional `Pin<ImplicitlyPinned>` is useless. In
> + /// doubt, the type can just be set to `Pin<Self>`.
> + type PinnedResult;
> +
It's unfortunate that we can't use an associated type default here.
Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Alice