Re: [PATCH v2] rust: Implement the smart pointer `InPlaceInit` for `Arc`
From: Benno Lossin
Date: Thu Jul 25 2024 - 14:06:20 EST
On 19.07.24 21:22, Alex Mantel wrote:
> diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs
> index 68605b633..46f50cf12 100644
> --- a/rust/kernel/init.rs
> +++ b/rust/kernel/init.rs
> @@ -213,6 +213,7 @@
> use crate::{
> alloc::{box_ext::BoxExt, AllocError, Flags},
> error::{self, Error},
> + sync::Arc,
> sync::UniqueArc,
> types::{Opaque, ScopeGuard},
> };
> @@ -1112,11 +1113,15 @@ unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> {
>
> /// 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>`.
This comment should better describe the purpose of this associated type,
the first line could be "Pinned version of `Self`" then (with an empty
line in between) you could write more explanatory stuff. I would also
rephrase what you have above, for example: "If a type already implicitly
pins its pointee, `Pin<Self>` is unnecessary. In this case use `Self`,
otherwise just use `Pin<Self>`.".
> + type PinnedResult;
I don't really like the name for this, since it is not a result. What do
you think of `PinnedSelf`?
Otherwise this looks good!
---
Cheers,
Benno
> +
> /// Use the given pin-initializer to pin-initialize a `T` inside of a new smart pointer of this
> /// type.
> ///
> /// If `T: !Unpin` it will not be able to move afterwards.
> - fn try_pin_init<E>(init: impl PinInit<T, E>, flags: Flags) -> Result<Pin<Self>, E>
> + fn try_pin_init<E>(init: impl PinInit<T, E>, flags: Flags) -> Result<Self::PinnedResult, E>
> where
> E: From<AllocError>;
>