Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1939324lqb; Mon, 27 May 2024 02:33:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWGR6ATKNKz6+kalU1KLXadSbyz9IkvjetXdAkDyqWOQbdx4LcxlBWXiJ3kQroBbTwtEF92YrjH8bGN6Q1HjNrLCVrkLgwdRalOCkoEOg== X-Google-Smtp-Source: AGHT+IGW4vfbsbwb18s8X1hp/zH364c8fFLvu56+aQbSDP5KxFi+psbTOKUjrvHv24IxNX++0yQU X-Received: by 2002:a17:906:490e:b0:a62:2cae:c02 with SMTP id a640c23a62f3a-a6264f01537mr603114766b.61.1716802400511; Mon, 27 May 2024 02:33:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716802400; cv=pass; d=google.com; s=arc-20160816; b=w6QijpW4acg4+dkNFai18hN2LHMPXpF4tVGLfCMZKIvnxMr5jCoOrqU/L0PDLeuix1 6Z1dUtsLCP4daMsA1PV3U6aif6Tl+ZtxTlS9nN7Pz2xQsYwOPE/0H/5TzG0+t14Yy44w y2lZCkdOvBjM8ouC7m3svegCBUyBLRtW9S6UeA24R9cqBfFKXyI1k0RokPjefMWR/Sms DWO6y9YuIPoT8T/oFYyu2gaot7Zih+9nwtni7dDKH1hbIFvQAq3XGUaWvxxrmUgjsPnG TPknmPu1g3ekBghg5p6uxQXxqucmUn8koeNhaGAp6xj6ecZ0H4K8FCy0VMvhkBsuGecG cirQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:feedback-id:references :in-reply-to:message-id:subject:cc:from:to:date:dkim-signature; bh=5Oa3A89J8+5axYPE1P3GO1ihKzX85SeBoOVRylK7fAM=; fh=1eN+strsLnX8cuvE+uTff7wY1KiEAf1jFO97IDCVf3U=; b=x7ycLlEgjWXqdV5au2uYcpvgyjrFq/r3eAH8Y6vMFpOKbMer8xbbfLQWIPy6HLTAjq mcaySh4/77rADYAIWBhlRnSBAjB8Qurx1RHiwA7KJ+gPjusCsmXbq04OrRpObXB9SIE2 UZWBkm8JTFW3btPN/npjuYdqgCY5rVrB4JAvFRJmBRmq8wZNW7mg/XxesLAelA3ExfGp 6M7Mv4VNredUjtKv++x/hEjq+CWK6bFYiq3/Vl37PR+qgYs7Z63v7LYs7gT9pq86Dn6U J9uVdYoM0h6uyaQ1NrpqG/CRA+D7KMkVhsFjhei5snag+nMUmXjwlgl03qsqwfIY08Hb BlMQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@proton.me header.s=x4b5jwmoy5he5m5aofddcrodj4.protonmail header.b=ObSnODJy; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-190317-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190317-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a626cc3818fsi348892666b.302.2024.05.27.02.33.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 02:33:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190317-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=x4b5jwmoy5he5m5aofddcrodj4.protonmail header.b=ObSnODJy; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-190317-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190317-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id EA0121F24624 for ; Mon, 27 May 2024 09:26:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5439913A269; Mon, 27 May 2024 09:25:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="ObSnODJy" Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 389C813A268 for ; Mon, 27 May 2024 09:25:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716801929; cv=none; b=EMrUx0JniaKL8uLnnJRiNKf77zlrqhxxvOXLnDzoY1Hky9rcyKhepEzcSQDdIBN+P3wgQosc1gOype661wYFmwqka2HPPj5TCPmvz6tOeNU3VaFhc1wqtehcypPx9M6hWasA8scOcF07gTY03+wTx9k39V8SXPbg9sIjYX5d7fo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716801929; c=relaxed/simple; bh=MoYpXoQd6dgd1S+BiMwm5EnBhyCwhBKy+on1h+PnKXI=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nr4C3rrih0fDjykPGguJ8r9NNvDmKanIGZkHFaU2OZoejcinAyprujUA8oB6KgfkhMDlGB5FzSiTIo8SvPf73RAd0jiVXDJ5lJfkIsDVQiSIaJS8Y2pPOfBBxz8OAa79vpObm5lUzL103D4/nPBpzYVuXOoWStj9VdCvqr+d98M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=ObSnODJy; arc=none smtp.client-ip=185.70.43.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=x4b5jwmoy5he5m5aofddcrodj4.protonmail; t=1716801919; x=1717061119; bh=5Oa3A89J8+5axYPE1P3GO1ihKzX85SeBoOVRylK7fAM=; 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=ObSnODJyiaLu9Jg6mPveTrmTzjetYQt6V2+zpd+OqLy90KQBT9zz/kCM9PD/9S1qA f/csl5QsY4Zkzn255uvdQ99mO0b3c/pjr5qDiym/hrWFMiqFwY5M+wDRFeR1PvWRdF hR/vmE5J1ePOWT7Q47crVCi959AbwSnt4Uzw8oR6aLY0pZWmu6Iml0dVK0lFMGNeW+ AUT1ZhwrXos4nC4x4jecCdGCUqaNo0VnzJazkzGyRJJmb5cysTQKm8jV/dEw4ivpah p2H6hIWnL6+OguPIO/j3cy/w0v8oLe3MYoJsGxYfvXkHy/aYElAYi4dBvLVNg+aKPp JX6irjOvV/1og== Date: Mon, 27 May 2024 09:25:16 +0000 To: Alice Ryhl , Miguel Ojeda , Andrew Morton From: Benno Lossin Cc: Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Marco Elver , Kees Cook , Coly Li , Paolo Abeni , Pierre Gondois , Ingo Molnar , Jakub Kicinski , Wei Yang , Matthew Wilcox , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Subject: Re: [PATCH v2 1/9] rust: list: add ListArc Message-ID: <3d04db54-8561-4c09-82c0-6ebcfb3e9ceb@proton.me> In-Reply-To: <20240506-linked-list-v2-1-7b910840c91f@google.com> References: <20240506-linked-list-v2-0-7b910840c91f@google.com> <20240506-linked-list-v2-1-7b910840c91f@google.com> Feedback-ID: 71780778:user:proton X-Pm-Message-ID: 8f4490f9c6da6cbc3385e001d019440362da4de9 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 06.05.24 11:53, Alice Ryhl wrote: > +impl ListArc > +where > + T: ListArcSafe + ?Sized, > +{ > + /// Convert a [`UniqueArc`] into a [`ListArc`]. > + #[inline] > + pub fn from_unique(unique: UniqueArc) -> Self { > + Self::from_pin_unique(Pin::from(unique)) > + } > + > + /// Convert a pinned [`UniqueArc`] into a [`ListArc`]. > + #[inline] > + pub fn from_pin_unique(mut unique: Pin>) -> Self { > + // SAFETY: We have a `UniqueArc`, so there is no `ListArc`. > + unsafe { T::on_create_list_arc_from_unique(unique.as_mut()) }; > + let arc =3D Arc::from(unique); > + // SAFETY: We just called `on_create_list_arc_from_unique` on an= arc without a `ListArc`, > + // so we can create a `ListArc`. > + unsafe { Self::transmute_from_arc(arc) } > + } I think these two functions would make sense as `From` impls. > + > + /// Like [`from_unique`], but creates two `ListArcs`. > + /// > + /// The two ids must be different. > + /// > + /// [`from_unique`]: ListArc::from_unique > + #[inline] > + pub fn pair_from_unique(unique: UniqueArc) -> (Se= lf, ListArc) > + where > + T: ListArcSafe, > + { > + Self::pair_from_pin_unique(Pin::from(unique)) > + } [...] > + /// Returns a reference to an [`Arc`] from the given [`ListArc`]. > + /// > + /// This is useful when the argument of a function call is an [`&Arc= `] (e.g., in a method > + /// receiver), but we have a [`ListArc`] instead. > + /// > + /// [`&Arc`]: Arc > + #[inline] > + pub fn as_arc(&self) -> &Arc { > + &self.arc > + } Should this be an `AsRef` impl instead? --- Cheers, Benno > + > + /// Returns an [`ArcBorrow`] from the given [`ListArc`]. > + /// > + /// This is useful when the argument of a function call is an [`ArcB= orrow`] (e.g., in a method > + /// receiver), but we have an [`Arc`] instead. Getting an [`ArcBorro= w`] is free when optimised. > + #[inline] > + pub fn as_arc_borrow(&self) -> ArcBorrow<'_, T> { > + self.arc.as_arc_borrow() > + } [...]