Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp148355rwl; Thu, 30 Mar 2023 13:35:42 -0700 (PDT) X-Google-Smtp-Source: AKy350ZXS3D/Qkr90AKLJueO1pUdPkiwunlqCHyvcrksbFGUb1LyMxGG/WNX/+rZNSABwLTACdb/ X-Received: by 2002:a05:6402:1e93:b0:501:ea97:5192 with SMTP id f19-20020a0564021e9300b00501ea975192mr26872602edf.4.1680208541885; Thu, 30 Mar 2023 13:35:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680208541; cv=none; d=google.com; s=arc-20160816; b=YVniqrRMZO/rfFNMgAxsOTiytgZJ9MLOhJFIKlOqRxMiPyDmXJpwZCJyp8jJiiC6lf 3UP7r1hIhLHVgRrDI1oN2YoqNIBerBxDt7VyuYvVtJ8pKYaCDt6bJGZkjXsEeXllnHZ9 e5FZwQf651CB2x8rfrWgmAjlT1xFfkyMnBGUmwCp6RnZm0yyJc7uD6/2onGH51F3Uxap ac+sxpSWgn7nzJRrdLGfnbPkzvsi3OATuhVXUdf5we3XY5TAHatNesgMvuynE0yEdknA uuqLPYPciPK/lecX0xwWxxDixokMd4lx6XZ2dq297I0RxY353Yf2ZaClaRFDLUtsdHcR GzMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:feedback-id:dkim-signature:dkim-signature; bh=yo0C034vGSBxi+os4rgvPlo0nGFfVZiz3ZeZDUzAo6s=; b=e5+9io3BuJsTtpoWOkcRxm7A8+hU6TPzXY9IWEJ6+2ogw7tUAmnJEIHjpz4zcqNKtq H27I8hLZHkOV5aT8o1uIrRnweSU5gOtt68AvR9EJwYZtH9LRrp2YF9uBYxiFn/exxHfo TN70+SoR8FJxsyhoNgkBurPwKkJQ/lwhlaGEQ3aPjJuOc1BakULvszuQqWg+4VBn2iy2 ll6rgQDKvF247fe69TYeSd2O5zPVJBB/VHEfA4NezK8wcigEmnM9aKR4WIzBevlxFANj ZNkyJzUWVeNPjgcNJiqYiiR1G8ch9FkLPFi9LoSyVJzDFH24BBa1iz5GVrJ9D54yj1DD saBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ryhl.io header.s=fm2 header.b=nOg05TAv; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=Hf4xg2ZR; 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=NONE sp=NONE dis=NONE) header.from=ryhl.io Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g3-20020a17090670c300b009474eb6719fsi389118ejk.1010.2023.03.30.13.35.16; Thu, 30 Mar 2023 13:35:41 -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=@ryhl.io header.s=fm2 header.b=nOg05TAv; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=Hf4xg2ZR; 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=NONE sp=NONE dis=NONE) header.from=ryhl.io Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229676AbjC3UZD (ORCPT + 99 others); Thu, 30 Mar 2023 16:25:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229521AbjC3UZC (ORCPT ); Thu, 30 Mar 2023 16:25:02 -0400 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EF541FE7; Thu, 30 Mar 2023 13:25:00 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 4D886320095E; Thu, 30 Mar 2023 16:24:57 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 30 Mar 2023 16:24:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ryhl.io; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1680207896; x=1680294296; bh=yo0C034vGSBxi+os4rgvPlo0nGFfVZiz3Ze ZDUzAo6s=; b=nOg05TAvugjNHAwkD3hyb0R1J5DEk7CRznYnzN5yw0NWL10NJzN z3M9Zh5rNeVOAa6UldhwinRCmVCMOvuD+ojq45oYGORIjyI5XQ1WFOg84piAUKpN kFpdzqcxc2W/am+mqyUVlymv4StJurYHgeO5sfxQKGJqReJx6wATUzrp4tm5Qwdm TXHjpFOpMt8q9ecYyh2gMjnzneF+udKQVM+ielJig/6VmcCEx8k6dOGH51fcg9ke Nz42HjIOlIUIe5/QF5r8/fomql7mBzEV0Q0wkCp8iEVFj0CVhlgeiQbymcUr75Q3 rzjEZG4vndYKPXC66yFO+65bHaXA64vwmfA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1680207896; x=1680294296; bh=yo0C034vGSBxi+os4rgvPlo0nGFfVZiz3Ze ZDUzAo6s=; b=Hf4xg2ZRLnr4FEdB89FkRxOtOh1rC5R3F5xNZIAUVjgavUdhIuz HUQZyUtvXtMWtMVZGzXicqTeYukba/uR54NxYldr7ULZW5nOGfVRIY84/d7KA4Gg QpQeszMbTPMYpchPb5wXxykOhGFf1PBbkL7ypdo190jdDb+iG6U9sSYpGkI1kF9n w63pIoFIcY7mdUbRbFIdloYFNnvG4FBHY4B5D8OLZoTD3xOCbMGChy8WYaI8J0iK +8E24zKrSR0lGUd6yMZNE5EhESwA8OO638GR6KharmlgGC6NrR4E8zingV0H/96N 7R5CLhsdH9cmzhXqjnTl7Bq7prCE6wZVlyw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdehledgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtfeejnecuhfhrohhmpeetlhhi tggvucfthihhlhcuoegrlhhitggvsehrhihhlhdrihhoqeenucggtffrrghtthgvrhhnpe fhtdfhieejveekgfevfedvieefhfeggeeiieehhfffleeuuddugfejleelkeffieenucff ohhmrghinhepughotghsrdhrshenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpegrlhhitggvsehrhihhlhdrihho X-ME-Proxy: Feedback-ID: i56684263:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 30 Mar 2023 16:24:54 -0400 (EDT) Message-ID: <1c2338c5-adab-f85c-645e-44e361ef0677@ryhl.io> Date: Thu, 30 Mar 2023 22:24:53 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH v3 06/13] rust: init/sync: add `InPlaceInit` trait to pin-initialize smart pointers Content-Language: en-US-large To: 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?= References: <20230329223239.138757-1-y86-dev@protonmail.com> <20230329223239.138757-7-y86-dev@protonmail.com> <1f93a045-5bd8-e07f-cf1b-7b1196c8ab54@ryhl.io> <3ea5cd8d-84ca-59bd-de50-fef185233a50@protonmail.com> From: Alice Ryhl In-Reply-To: <3ea5cd8d-84ca-59bd-de50-fef185233a50@protonmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, 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 3/30/23 17:28, Benno Lossin wrote: > 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 Ok, if my alternative causes type inference problems, then let us keep the version you proposed here. We can add more variants later. (Or if you want to add more now, that's also fine.) Reviewed-by: Alice Ryhl