Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2301526rwl; Thu, 30 Mar 2023 08:31:59 -0700 (PDT) X-Google-Smtp-Source: AKy350bhYkgC/cUHVqYhCE8/sKSzUTJepvG4fUyTkzDGwyeGa3kcUWgw+Fziv2qN8CEQ7XXon24X X-Received: by 2002:a05:6402:268e:b0:502:1f7b:f0a6 with SMTP id w14-20020a056402268e00b005021f7bf0a6mr24971894edd.0.1680190319444; Thu, 30 Mar 2023 08:31:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680190319; cv=none; d=google.com; s=arc-20160816; b=DwQ2w1IglL+POdFC/tsOpTET2FTS2dbPN8KsOPgamqCI67Q8Bbtom1BFixG3KDjW7+ kg0l9FHukaQ9a7tX8oGzCMPTDjEdMs7DQCE5Zs8jvCnueE7fmgnnlht0zRVMfLn5QmB8 Nn+7fpezHV85VJbisOrxRu26Sz1V/fLi17zZGDSetD2KEmX8h/Sgnrx42dc9IoDdYlAa 6E//vs4L3pclJAjS4s0Dc8y9QOCtra3EfUeYdxfNlKaLvqZLNfsvmR2mSl3Bo8eWKlTk Zq0670Ulc1eaEu8A9tSCxP1XUySUzFuasE0mkAZtICcWW1Uk3iqAycysdsPeoJNv5vvD 8JgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :dkim-signature:date; bh=kpaOTyrKqsw1XHAwXmaqpibdDWFN/5HsmHgDh0lZUrg=; b=uZBbwYUX+2DYdZKmm0V2zlys4wg5QPCA2tD/mfU+vYj896vL6p/p7Wogi50hBJBSGq wNlXARHx+5jpE+BLQRCxZjsb4+MrXp7vc32AR61Hv8zvm+XOtdSHoVKBIaTcnrr5JAEB jGpNNZCMQolwRn8bXbEGi0ZxhI1wNEgZcAaA1kOAgLpRzNwFYXG1wYPfjAcx6yUrgKxb s17lYXrMfdbkcXP/RHNjoyUMngPyF5iuEhkinnU3xyLqlclyP20AML/vM4OGEE3JLE6f QZhd+cACvkO7Wp8bI3c/DoZ53ajGY0/n5bxonFtJhbikChiKuUYnch47klkS1tcpdvxP Bu0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=odsQp3ku; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l8-20020a056402124800b004cdc92cc412si70628edw.69.2023.03.30.08.31.29; Thu, 30 Mar 2023 08:31:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=odsQp3ku; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232978AbjC3P33 (ORCPT + 99 others); Thu, 30 Mar 2023 11:29:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232993AbjC3P3V (ORCPT ); Thu, 30 Mar 2023 11:29:21 -0400 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C033E04F for ; Thu, 30 Mar 2023 08:29:03 -0700 (PDT) Date: Thu, 30 Mar 2023 15:28:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1680190102; x=1680449302; bh=kpaOTyrKqsw1XHAwXmaqpibdDWFN/5HsmHgDh0lZUrg=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=odsQp3kuPYH79BQTdgIjYANBF/X5AwTkHo+Rx+bFHO+jN8jDLzyn/3n3aV3s5tX+S bUUbfGNFYEz9U7kyM7IJxHptVFFoh9xJC4OzG2tvcX1aPlBVT/Og0t42oiFq7VX4bg ZNv1QBD/PHk8n6EFgpLYq9lECnxEvb2FZUPbXGr84UXs82YAm34zWk/lDWt2B0CjX5 5bdOAOi5zwpCtvpYrEonpP296gvgJRfTzA5j6qTMwkcV8tsfo5j2vikdhtAGEuEIvb NctaMjaE+N187DL9lX+jQES9OGdzCMkWerxcpRStLoDW5fuvSgc/KxVGiz72rdeSv9 h3hthoAXLcpPA== To: Alice Ryhl From: Benno Lossin Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= Subject: Re: [PATCH v3 06/13] rust: init/sync: add `InPlaceInit` trait to pin-initialize smart pointers Message-ID: <3ea5cd8d-84ca-59bd-de50-fef185233a50@protonmail.com> In-Reply-To: <1f93a045-5bd8-e07f-cf1b-7b1196c8ab54@ryhl.io> References: <20230329223239.138757-1-y86-dev@protonmail.com> <20230329223239.138757-7-y86-dev@protonmail.com> <1f93a045-5bd8-e07f-cf1b-7b1196c8ab54@ryhl.io> Feedback-ID: 40624463:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 30.03.23 16:37, Alice Ryhl wrote: > On 3/30/23 00:33, y86-dev@protonmail.com wrote: >> From: Benno Lossin >> >> The `InPlaceInit` trait that provides two functions, for initializing >> using `PinInit` and `Init`. It is implemented by `Arc`, >> `UniqueArc` and `Box`. >> >> Signed-off-by: Benno Lossin > > --- > > >> +/// Smart pointer that can initialize memory in-place. >> +pub trait InPlaceInit: Sized { >> + /// Use the given initializer to in-place initialize a `T`. >> + /// >> + /// If `T: !Unpin` it will not be able to move afterwards. >> + fn pin_init(init: impl PinInit) -> error::Result= > >> + where >> + Error: From; >> + >> + /// Use the given initializer to in-place initialize a `T`. >> + fn init(init: impl Init) -> error::Result >> + where >> + Error: From; >> +} > > This definition is potentially rather limiting, because it can only be > used with error types that can be converted into a `kernel::Error`. What > do you think of this alternative? > > pub trait InPlaceInit: Sized { > fn pin_init(init: impl PinInit) -> Result, E> > where > E: From; > > fn init(init: impl Init) -> Result > where > E: From; > } I initially implemented it like this, but it required almost always that `E` is specified, I will try and see if the situation is any different now, but I do not think so. In the user-space version of this API (see [1]) I have four functions, normal variants that return an `AllocError` and `try` variants that look exactly like what you suggested. In the kernel, we could make the normal variants as they are now and add the `try` variants as you described. [1]: https://docs.rs/pinned-init/0.0.5/pinned_init/trait.InPlaceInit.html -- Cheers, Benno