Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2234802rwl; Thu, 30 Mar 2023 07:45:25 -0700 (PDT) X-Google-Smtp-Source: AKy350ZHmq4B3lslwNdkH9wq8f7A8RzeC3n6kBtwdpdrMpe2OMXjS9Uti940ysqX0WfTRPrQf76D X-Received: by 2002:a05:6a00:450e:b0:625:a08c:a8ba with SMTP id cw14-20020a056a00450e00b00625a08ca8bamr21629421pfb.1.1680187525021; Thu, 30 Mar 2023 07:45:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680187525; cv=none; d=google.com; s=arc-20160816; b=n2PRSZT2vRwDFoZfhl0kTdALUluxMQXqwvudVIpyUW9+zYBOCGu+nHP3CSyZDVTWlU 1APKH25B8pTtRvcGiToGxrCGqQmv50A9DTHoVg9CrrF7gS6yPcY6fpzorURqMlc5z/PB +sKZFkgVolbwL6iLQ0oqMh15x86nc6sg2D5A0GIODooumQsb20WxiBS4cVp/CBW9ScwF xVOK5ciKu0hFdZ8JRamlmvYf+AEI+GbXUtZWpwhpdCI5WGXR1YBDs28DWnu+gTtLgs4+ e0RDZoXFrh6E2YDl5X35pnuz+nbXnTK/PAF1z8jCKmsfBn/1TOeEX+nYQQtwQueDxEAx DrlQ== 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=aaHDnGEY8jQWwBiHM0AomkpCoN/1r8C0yPkRgo7kzOI=; b=VctTb2mrX5dNVvEqB1UmitTEEjBuAxfOIj/8mnTRGWj6ja4HsdEPzPBBF7xN3WVGTm 12k6rAaqFvAYuUk6Gu/FkG2inP63x5pzBpD/PFs0s3Iu8mF7pxSJsDaIbZH8ttbM8VFF lIlXImuGx5txelF5jsYgO/Q9b97Toy83CEG7jTZYo8S+JWu+QKzFLAW50i3NjYp+Jf2e ZEm983c2IiKLwKUjNdK6fGz9n/h0zAr0n9zH5PdZkJQYWMoyNiealvwhcqYESp8gcI5M 4S38E20T8w1PpVdw7/AQ72gmCPi9hjUdUgGhKKuR/IC8B0lM9AV8rftMtuwx1uBqbBSY elfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ryhl.io header.s=fm2 header.b=EHkKTUkv; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=K3sAiPnw; 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 q3-20020a056a00088300b005808bb470a0si34443123pfj.180.2023.03.30.07.45.11; Thu, 30 Mar 2023 07:45:24 -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=EHkKTUkv; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=K3sAiPnw; 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 S232440AbjC3OWa (ORCPT + 99 others); Thu, 30 Mar 2023 10:22:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232452AbjC3OW1 (ORCPT ); Thu, 30 Mar 2023 10:22:27 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C776C65F; Thu, 30 Mar 2023 07:21:54 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 3A9893200495; Thu, 30 Mar 2023 10:21:29 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 30 Mar 2023 10:21:29 -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= 1680186088; x=1680272488; bh=aaHDnGEY8jQWwBiHM0AomkpCoN/1r8C0yPk Rgo7kzOI=; b=EHkKTUkv+ZU6d642PnmpxtLiefd1jLRa6aLEbIBZJ//Xw7xFb6c ocJWhL+RgkKFlpAUPpap17tuAX81odULLYvUU91brxOKbxnj0nrqy9MElOcKFGVn bO9cNNZ77tYEAC0zALL5UM84t9+CpLJw6oulVqFL9wheqoeAfer1QlWYWQqfPjK0 LkQ3ry/O5qcyo1Ui7NRTlIcgU1n46LjvSE3O9+eJMM0KStMZ1RvFhEt07zeHKLiz NeiR9XwLlErMq+WEXJXkjbLMxv2vYVs36FE5bioe3jL/ddC321lxxJGMtauMfK2Q pFDH1IK1DI/6HfMx9aDZEPdPx36Rlx6oimQ== 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= 1680186088; x=1680272488; bh=aaHDnGEY8jQWwBiHM0AomkpCoN/1r8C0yPk Rgo7kzOI=; b=K3sAiPnwAgatkHpndFCVM+oXEIgS85j2P85doaM33lDqwSPc01x UhocjnwJrul9UKtXn3u6JOWP0Vqm6ijMCalG2RbLG3vVbzyI4BgmL9Eji9YKj28r IZCStdV8LizaemXBFYXWhbrhgDd88gPfWqvj0saeO1fDSmkpsbhHr2H4cnK/v8Ci +hFXtrWb6wW24aKjs+IWdXmQTqIrMxyGK7gvFIPWLSjUJlMzrZv2bHe80bhniER6 c/nmId1wTut389t9YuZECQkyw067UJW0AckXkyJ1fgV5zFNyaYDLZx+NPx+Ibs6U 7XyEuL6e02QN+RsQ/ow2v7A9BMIiNEtLiTQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdehkedgjeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtfeejnecuhfhrohhmpeetlhhi tggvucfthihhlhcuoegrlhhitggvsehrhihhlhdrihhoqeenucggtffrrghtthgvrhhnpe ehudduvdetkedvkedtudeludfgfffhudegjeeguedvvedtteevjeehheeiffefgeenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhitggvse hrhihhlhdrihho X-ME-Proxy: Feedback-ID: i56684263:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 30 Mar 2023 10:21:25 -0400 (EDT) Message-ID: Date: Thu, 30 Mar 2023 16:21:37 +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 05/13] rust: init: add initialization macros Content-Language: en-US To: y86-dev@protonmail.com 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-6-y86-dev@protonmail.com> From: Alice Ryhl In-Reply-To: <20230329223239.138757-6-y86-dev@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 00:33, y86-dev@protonmail.com wrote: > From: Benno Lossin > > Add the following initializer macros: > - `#[pin_data]` to annotate structurally pinned fields of structs, > needed for `pin_init!` and `try_pin_init!` to select the correct > initializer of fields. > - `pin_init!` create a pin-initializer for a struct with the > `Infallible` error type. > - `try_pin_init!` create a pin-initializer for a struct with a custom > error type (`kernel::error::Error` is the default). > - `init!` create an in-place-initializer for a struct with the > `Infallible` error type. > - `try_init!` create an in-place-initializer for a struct with a custom > error type (`kernel::error::Error` is the default). > > Also add their needed internal helper traits and structs. > > Co-developed-by: Gary Guo > Signed-off-by: Gary Guo > Signed-off-by: Benno Lossin Reviewed-by: Alice Ryhl > +/// ```rust > +/// # #![allow(clippy::disallowed_names, clippy::new_ret_no_self)] > +/// # use kernel::{init, pin_init, prelude::*, init::*}; > +/// # use core::pin::Pin; > +/// # #[pin_data] > +/// # struct Foo { > +/// # a: usize, > +/// # b: Bar, > +/// # } > +/// # #[pin_data] > +/// # struct Bar { > +/// # x: u32, > +/// # } > +/// > +/// impl Foo { > +/// fn new() -> impl PinInit { I would remove the empty line above `impl Foo` so that the example doesn't start with an empty line when rendered. > +/// # Syntax > +/// > +/// As already mentioned in the examples above, inside of `pin_init!` a `struct` initializer with > +/// the following modifications is expected: > +/// - Fields that you want to initialize in-place have to use `<-` instead of `:`. > +/// - In front of the initializer you can write `&this in` to have access to a [`NonNull`] > +/// pointer named `this` inside of the initializer. > +/// > +/// For instance: > +/// > +/// ```rust > +/// # use kernel::pin_init; > +/// # use macros::pin_data; > +/// # use core::{ptr::addr_of_mut, marker::PhantomPinned}; > +/// #[pin_data] > +/// struct Buf { > +/// ptr: *mut u8, I'd add a comment on the `ptr` field saying "points at `buf`". > +/// impl BigBuf { > +/// fn new() -> impl PinInit { > +/// try_pin_init!(Self { > +/// big: { > +/// let zero = Box::try_new_zeroed()?; > +/// unsafe { zero.assume_init() } > +/// }, Is there a reason for not using `Box::init(kernel::init::zeroed())?` here?