rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benno Lossin <y86-dev@protonmail.com>
To: Boqun Feng <boqun.feng@gmail.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Wedson Almeida Filho" <wedsonaf@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Alice Ryhl" <alice@ryhl.io>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	patches@lists.linux.dev,
	"Andreas Hindborg" <a.hindborg@samsung.com>,
	"Alice Ryhl" <aliceryhl@google.com>
Subject: Re: [PATCH v4 08/15] rust: init/sync: add `InPlaceInit` trait to pin-initialize smart pointers
Date: Sat, 01 Apr 2023 07:44:32 +0000	[thread overview]
Message-ID: <90c7c075-255e-33ef-527e-32be5e9a6fc3@protonmail.com> (raw)
In-Reply-To: <ZCdh8fwSGTjDW6vE@boqun-archlinux>

On 01.04.23 00:42, Boqun Feng wrote:
> On Fri, Mar 31, 2023 at 09:53:25PM +0000, y86-dev@protonmail.com wrote:
> [...]
>> diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
>> index eee7008e5e3e..24dc96603090 100644
>> --- a/rust/kernel/sync/arc.rs
>> +++ b/rust/kernel/sync/arc.rs
>> @@ -17,6 +17,7 @@
>>
>>   use crate::{
>>       bindings,
>> +    init::{InPlaceInit, Init, PinInit},
>>       types::{ForeignOwnable, Opaque},
>>   };
>>   use alloc::boxed::Box;
>> @@ -163,6 +164,28 @@ impl<T> Arc<T> {
>>           // `Arc` object.
>>           Ok(unsafe { Self::from_inner(Box::leak(inner).into()) })
>>       }
>> +
>> +    /// Use the given initializer to in-place initialize a `T`.
>> +    ///
>> +    /// If `T: !Unpin` it will not be able to move afterwards.
>> +    #[inline]
>> +    pub fn pin_init<E>(init: impl PinInit<T, E>) -> Result<Self>
>
> `Result` became `core::result::Result` after patch #3, so you will need
> to refer to `crate::error::Result` here. Alternatively you can change
> patch #3 to use the full path i.e. `core::result::Result`.
>
>> +    where
>> +        Error: From<E>,
>
> In my env, looks like the compiler doesn't know which `Error` it
> is after removing use of `crate::error::Result` in patch #3, you
> probably need to deal with this as well.
>
> Regards,
> Boqun
>
>> +    {
>> +        UniqueArc::pin_init(init).map(|u| u.into())
>> +    }
>> +
>> +    /// Use the given initializer to in-place initialize a `T`.
>> +    ///
>> +    /// This is equivalent to [`pin_init`], since an [`Arc`] is always pinned.
>> +    #[inline]
>> +    pub fn init<E>(init: impl Init<T, E>) -> Result<Self>
>> +    where
>> +        Error: From<E>,
>> +    {
>> +        UniqueArc::init(init).map(|u| u.into())
>> +    }
>>   }
>>
>>   impl<T: ?Sized> Arc<T> {
>> --
>> 2.39.2
>>
>>

Sorry, forgot to compile check that.
--
Cheers,
Benno



      reply	other threads:[~2023-04-01  7:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-31 21:53 [PATCH v4 08/15] rust: init/sync: add `InPlaceInit` trait to pin-initialize smart pointers y86-dev
2023-03-31 22:42 ` Boqun Feng
2023-04-01  7:44   ` Benno Lossin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=90c7c075-255e-33ef-527e-32be5e9a6fc3@protonmail.com \
    --to=y86-dev@protonmail.com \
    --cc=a.hindborg@samsung.com \
    --cc=alex.gaynor@gmail.com \
    --cc=alice@ryhl.io \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=wedsonaf@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).