Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp8784948rwl; Sat, 31 Dec 2022 11:54:37 -0800 (PST) X-Google-Smtp-Source: AMrXdXsi8wkvs5RzPuk1Z/pQSuwT7ySROnygBB/6KB5rKxm3LnWd79RmwdOb5xuiBPkDqjq/vOH5 X-Received: by 2002:a17:907:9d19:b0:7b9:f9d8:9554 with SMTP id kt25-20020a1709079d1900b007b9f9d89554mr28123459ejc.40.1672516477196; Sat, 31 Dec 2022 11:54:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1672516477; cv=pass; d=google.com; s=arc-20160816; b=WFLFxzl8jdl/n72PD+ngGKHlNZN/Tzz10Sp0BZjuTRNba9eNG85go2jhWSoyyqlV/K zOtIURfYO4a5odQneZrzUPfwTwk/IQP+oY+OwvFt5BjYdCskkvvKTgxEAAVPjorHrcu1 XWg2oQBr3uLZiROj4yJUjgDjJ8rkR4jP86ONfgP1WxFAE3bstcdlXq0vk1uP2W+1EqPB 3IpJuwaMYm90a3Cfe7Ps3JWP7WcafLm6P9047k7TD7S+MA+gOviLjgHb19P1zHd5LTNT MBd8GVqi9g4UGWud39nQuizYl78FcocuIXUCCNF19I+aKibjUPwjKOUcU6tk00cv7zeK 4I9w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=naNmoFFCnHryiWah+9xPm7ecd2I5OBm81O4dYwxmo+s=; b=AzNs07P86UOAWS05TkagoI5QUNm41AW5Z9b/2BZtFtZ0XaEdEcYUFzgFlphgUGZcu/ ZxX5M/nOaAUrQ0NwmWdsDla3YHPPupzfgxY8S9VfQ0SCPU43THU640dvtpajec+wN01X aICX3dWB1g6y0EnI8H8GyiB9jEK5djtS520J2KTNRguwNxtU2NALDzvWSNJMmXccXeJm R+DNt2hPXQAJ6bn3Iy5ukubJdhI+tArcKCM2nyWm3Y6U5EGDo6c7Nba5KCUCtPF+Cc8U 4S25ULuJAtTwcteu/2eviEQIgv6PZo2jcvUZf8uF1GDJzqfrksgkYyC1uqAJmV9pD6Am rNHA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@garyguo.net header.s=selector1 header.b=Xad4kA9n; arc=pass (i=1 spf=pass spfdomain=garyguo.net dkim=pass dkdomain=garyguo.net dmarc=pass fromdomain=garyguo.net); 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id un2-20020a170907cb8200b007c4fb520308si16557259ejc.945.2022.12.31.11.54.23; Sat, 31 Dec 2022 11:54:37 -0800 (PST) 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=@garyguo.net header.s=selector1 header.b=Xad4kA9n; arc=pass (i=1 spf=pass spfdomain=garyguo.net dkim=pass dkdomain=garyguo.net dmarc=pass fromdomain=garyguo.net); 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232038AbiLaToU (ORCPT + 61 others); Sat, 31 Dec 2022 14:44:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232382AbiLaToS (ORCPT ); Sat, 31 Dec 2022 14:44:18 -0500 Received: from GBR01-CWL-obe.outbound.protection.outlook.com (mail-cwlgbr01on2107.outbound.protection.outlook.com [40.107.11.107]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CADFC5581; Sat, 31 Dec 2022 11:44:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iercTrTs/e94+oCNe5Y9XZyq07Ry0vO8Hm0Y4qaw6iEFvOKp+pqDuOcntj1Ps/Vyt9ZOEtadkPgh2utWVyetWEJ7KoIOQbmDM8Qd8AOBm+dU/N1CzyTtQGMFhz4fU2WWOJWlBX97dJLjaXVWg4OGE9SnzP75DkngXlUdsYaHiBOyNE0h55DOTy0/RYSiHYn/5cT+mjzcNjw88ifCHd8FSSwTnDcowGhYxObNxk0wBqYYNsZY6IAqyPSfsEGAH4T9Oh6Ubo9y/K7nv1aUJA3vf2Eb5CTGQmbpx3laQkFZ25PeFIVC3s32dlcQT3h5wEDPDZf5qApOfOLzec1ucB4ARw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=naNmoFFCnHryiWah+9xPm7ecd2I5OBm81O4dYwxmo+s=; b=T94pC/ulD/WJ+Ffh1erLyCt7d1oc0pH81U847U2Oqrag/+QeUA+wEihbl8981ehLft7osuuXfcNshzM6JyMCuToDmI2kCBj+0zekUCdm444f90Dg+BlNOtkBpvQ9IE1TDa83OclQTMG9JHqAU6/3ODG3nk/yVhs5JODAKXjtxhUsYP0GiP1BfReKqvp08AhUX+8KKtOqjW2jwnhScEosna4nNwTs5qV+DvK/eZNyJp+FRCUA11AG8NC9xxyWHRA2ZoqsHsrOlGvrurroH6KHOQWsumZxml3OOha8VWzQABHTLv1Ad11RQ3MWQnF9MBLryL9iAxhJxSZAa1lWjOWf2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=garyguo.net; dmarc=pass action=none header.from=garyguo.net; dkim=pass header.d=garyguo.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garyguo.net; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=naNmoFFCnHryiWah+9xPm7ecd2I5OBm81O4dYwxmo+s=; b=Xad4kA9ngkOlqWr0cE6m9spij8HjeovhYrKWrUjieH73xIX6qOT1IKjbKx003OR0eLruWxSoCx7pJwz3/cfjeFX2/mzvzM5EoJrkMd5nFKpatPBWVg2zcfn0clzPFnQ2G1XSPwpnADcuJW7SLZi73+yqkR6BBy6Wrlm4CREriBc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=garyguo.net; Received: from LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:253::10) by LO6P265MB6473.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2dd::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.18; Sat, 31 Dec 2022 19:44:15 +0000 Received: from LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM ([fe80::2f24:8099:5588:8ba8]) by LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM ([fe80::2f24:8099:5588:8ba8%8]) with mapi id 15.20.5944.018; Sat, 31 Dec 2022 19:44:15 +0000 Date: Sat, 31 Dec 2022 19:44:14 +0000 From: Gary Guo To: Wedson Almeida Filho Cc: rust-for-linux@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Boqun Feng , =?UTF-8?B?QmrDtnJu?= Roy Baron , linux-kernel@vger.kernel.org Subject: Re: [PATCH 5/7] rust: sync: allow type of `self` to be `ArcBorrow` Message-ID: <20221231194414.3f66d8af.gary@garyguo.net> In-Reply-To: <20221228060346.352362-5-wedsonaf@gmail.com> References: <20221228060346.352362-1-wedsonaf@gmail.com> <20221228060346.352362-5-wedsonaf@gmail.com> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.33; x86_64-pc-linux-gnu) Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO2P123CA0045.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600::33) To LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:253::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LO2P265MB5183:EE_|LO6P265MB6473:EE_ X-MS-Office365-Filtering-Correlation-Id: 6187456e-47bc-46df-39aa-08daeb6765e2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5ExK5cm0dM9X6Sfb8zSFKOZgxmBTgI6yyDhVjiy/eyVAWvG/KxjTYCSerZvyPamE/tBfXvcBbI0XdEA7OAKPakOxY5Z+jrlWOaHTOCYEgenxsiYpcinBd7a4bae5+bR/yGhQfZr9RkUIVuyyUc9QYAZ8BXW+YorWFZd6EU0OrRqDDvM4eusGH2sSzma66PYrLIIKva//ZnYTXhWXIvp/PbUNZb6GkYNu1dm7iBmtEgQEIinx92vPSw/b+ZGbIFeirQ/7YK8buv2wg2ZH5NoVMc2O+wHy40BtE6D2Q4q5fr1ehGr+LWNcxaaQLt2nNLm9JaEjrAxtR5iZ/RSHUbQ09qMMks/1u3MR/kasbHtmvz9iVVTbkpU+6o0AsJ7p8mxFSGyOOc/QWA65qJV2MkA+9kH7EkWC9A+a8gByf93uK25RzZaWuPgmeCy56hBS2Ia6cb+nHNHV8CPRRala3AOGvjlYjf9CnTsRZSS/LWO1n+v9M2CA4j4cgVjXSVsRJWuhhqXF9i7d2aUZsRzaUOQ8XQ6loLdCebmsMGrvFpyLRxbpW+1MicROHik+3Iek7yp4ypa8DDP1pPm7SQfJ+7zT4PbEkzZKR0oQ041zGvlV7A5i0HHbuc4tC94xjSudI14GyQlLezUncuxiHbrq/3ztbSW3H7+jhyv8aZueJRj4LDwUqXm5g6VTrnwaU3qKyqpd X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230022)(366004)(346002)(396003)(376002)(136003)(39830400003)(451199015)(26005)(186003)(6512007)(2616005)(1076003)(55236004)(6506007)(86362001)(36756003)(38100700002)(8936002)(4326008)(8676002)(41300700001)(2906002)(5660300002)(6486002)(478600001)(66946007)(316002)(66476007)(66556008)(54906003)(6916009)(81973001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?HN2tZEM7soJAPmgBoMyhoQkzoilYpe88//3VMYVUYFu0CUcYwnpL+isb63Bn?= =?us-ascii?Q?5oosSYAvtvALAfvNB/D65GCFKswbXm1PiDoW+yPbVuU5wdd9Q6MQrVwiEQnO?= =?us-ascii?Q?kEL2Te9oIO7DU5679P0p0gkP+QQW9jxjJlh/l2qvLObZMbltKHkLUnw9sjsU?= =?us-ascii?Q?zCMfXkxFrU9mErQnfR0xQeWxZ5I9yHFZuL1weNt9BdTWT+gPhNBqFerUlg8O?= =?us-ascii?Q?RRIgPwQKMLyJ0Eb9E4zUtA1BmxbxSWbdDmyE25vw6Jbwsswjj+EEY5m7WK22?= =?us-ascii?Q?AnUVydqESVBCmus2jl6aAcdx2I6cny5QlzDGphczZPcT5J1m6yQde1JPpSF6?= =?us-ascii?Q?ZJeSL+lmODZcdjCLKlDv0SdweHp1JmanSfaI26oUZUhatgDdM+BnqsezY6Qs?= =?us-ascii?Q?eNkveufnvYqua2+syIEwzoXBvuUW4sa4K2jctrbrJNERx/AoR0elQ9+GowVE?= =?us-ascii?Q?vVVdOMJ7LAG/PXYadfp/9rdiltsjysCwi9yRr9OEEduVAQyIl1UBr1HykIsw?= =?us-ascii?Q?UMrEbCUHXpqNNd03/jOqAVQZ9MEksOAKaUaxIoV3xP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Jx6muF/seZlLxDLPwEp6oLtmzM1WKr71/LxUnVgRTk7AXAVuyOENIa4?= =?us-ascii?Q?sIDzVpIE7z/DcY4gPnsKl79lAqiNwltC+7vk/tPt4rzJsk2iiYc3ZU21FlAk?= =?us-ascii?Q?4McbMOoy/l06HwPiG0U=3D?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: 6187456e-47bc-46df-39aa-08daeb6765e2 X-MS-Exchange-CrossTenant-AuthSource: LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Dec 2022 19:44:15.0923 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bbc898ad-b10f-4e10-8552-d9377b823d45 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: UTgtFbIeR+r2r6sgsT0/Y+IzKvxwuji6+N2t7gEByWpsEh5yegiWQRT5fIdzxbxPzicOWzF2z/b4jBiAkk5tdw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LO6P265MB6473 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham 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 Wed, 28 Dec 2022 06:03:44 +0000 Wedson Almeida Filho wrote: > This allows associated functions whose `self` argument has > `ArcBorrow` as their type. This, in turn, allows callers to use the > dot syntax to make calls. > > Signed-off-by: Wedson Almeida Filho Reviewed-by: Gary Guo > --- > rust/kernel/sync/arc.rs | 23 +++++++++++++++++++++++ > 1 file changed, 23 insertions(+) > > diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs > index f68bfc02c81a..84f31c85a513 100644 > --- a/rust/kernel/sync/arc.rs > +++ b/rust/kernel/sync/arc.rs > @@ -255,11 +255,34 @@ impl Drop for Arc { > /// // Assert that both `obj` and `cloned` point to the same underlying object. > /// assert!(core::ptr::eq(&*obj, &*cloned)); > /// ``` > +/// > +/// Using `ArcBorrow` as the type of `self`: > +/// > +/// ``` > +/// use crate::sync::{Arc, ArcBorrow}; > +/// > +/// struct Example { > +/// a: u32, > +/// b: u32, > +/// } > +/// > +/// impl Example { > +/// fn use_reference(self: ArcBorrow<'_, Self>) { > +/// // ... > +/// } > +/// } > +/// > +/// let obj = Arc::try_new(Example { a: 10, b: 20 })?; > +/// obj.as_arc_borrow().use_reference(); > +/// ``` > pub struct ArcBorrow<'a, T: ?Sized + 'a> { > inner: NonNull>, > _p: PhantomData<&'a ()>, > } > > +// This is to allow [`ArcBorrow`] (and variants) to be used as the type of `self`. > +impl core::ops::Receiver for ArcBorrow<'_, T> {} > + > impl Clone for ArcBorrow<'_, T> { > fn clone(&self) -> Self { > *self