Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2711592rwd; Wed, 17 May 2023 13:22:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7QQtv9xSNSGlOt9WbaEIHGL2hCn7Jj5xx72ug2QZluOnLcCCC+zt3Om1403CTFRusnIlKA X-Received: by 2002:a05:6a00:1749:b0:643:980:65b with SMTP id j9-20020a056a00174900b006430980065bmr1431854pfc.2.1684354934077; Wed, 17 May 2023 13:22:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684354934; cv=none; d=google.com; s=arc-20160816; b=sfkZB4QuKCLYtFw6oeK1kok/DjGoKYdqs8sXq/gCupxukp1kMadnJNg/XlLT0NOSoT GB4xGFm44w7tDQDHv1lCVrzhlFZmsc2JaOibYSQ9QN2et+gT4WKGvbxwZxUTnSx6zxto JsCgemJqZ3fxL3Y05KXXOa84zgf2wPCPPzje8L/eFfYvkdwlUHfSeAUJGCtoDxa+e6Jk mWQir5TsLOPVA25S3CTJD2UoF+EVJ2F9s6zcYohQrRnqopzPxzrHXpQnhyEw4nmh6++p mcB6gh6eRs992ypFO1pSrdfuL/GN9GsKwrxCSyiCzReRyQGdHGhKuN6mPX929LJFzqBI YelQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=8iJR0huTfHVTodkNfO2dbFSpbRb6U9pb/v/u0biFupw=; b=iCBlk4gLaEJCt9vjterGvdvW8RWPspTE6avE5tDavzZU42KEvBok/ZZoZn8ZwKWN+E ApybFq6xNC0kO9yPSwsqysPdOWzvshz9sINfOKY+GOTIURDP49/hLWWAjW8mBAE8uHKR aTH4yG83twO1Egt/V+xHSHl3mxdCX3GUz5UP9Udmk7LwYgi94gp1MjQei0RX0U9ZRzyF 4Rb3l1cQBTRI0D9KM7KuFc62XqjgeqBiRx5GKH9X/9o/7KohzZ0Mkh4B9DQ7/tcn9F7+ psiE3+JaeNfqF0VLwoVdDBTXh6eOlxZWaT68cuJXKiaN5zS2FGKBojgw8GQh6JWUVlUQ p4Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=bWzM94fI; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v7-20020aa799c7000000b006434e20d023si22222300pfi.399.2023.05.17.13.21.59; Wed, 17 May 2023 13:22:14 -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=@google.com header.s=20221208 header.b=bWzM94fI; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229519AbjEQUIn (ORCPT + 99 others); Wed, 17 May 2023 16:08:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjEQUIi (ORCPT ); Wed, 17 May 2023 16:08:38 -0400 Received: from mail-ej1-x649.google.com (mail-ej1-x649.google.com [IPv6:2a00:1450:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9B0C7D89 for ; Wed, 17 May 2023 13:08:37 -0700 (PDT) Received: by mail-ej1-x649.google.com with SMTP id a640c23a62f3a-94a34d3e5ebso131457666b.3 for ; Wed, 17 May 2023 13:08:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684354116; x=1686946116; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=8iJR0huTfHVTodkNfO2dbFSpbRb6U9pb/v/u0biFupw=; b=bWzM94fINtOQiMgIeij8r/YgZ5x9bR/Dr9fiTQjsYbOEc/EG/KK3e24KYDbSbKNXFq q0JETAcKy8aAdEveycELSQP0Ii/yRJnHVk4NKArscNFWSTQkCbq1VcORowwK/6Ou8Yb8 0s6z4qC2HG4wsDP+zgctkD2KNiocsj8sZviKvuD+KSI518NxZvqsWzw8HUxm1BcPU4eJ S3tGklnk97V3591mhv9OhfHFl38eoUwDL0WA8VbW30AEVdqh1K736UaBB1EKE5aaAvRJ RpxcN2gss1FGPI7JNDtmlPhXfX8KVUsqBfnaRMg0dauYa+JFHyIAHP4RRisrg0k+L8XF 1ugw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684354116; x=1686946116; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8iJR0huTfHVTodkNfO2dbFSpbRb6U9pb/v/u0biFupw=; b=WxVxN0at63RzQ/HqIhGi56zYvMhCPes60qqd7RA4kuYETeFy6FtZn1xw5C4d/Me4eG +1+iy2ljz0BQ15EcQjwB3Pf1fCwfF8KgbTdrlqsGBUfPAyyk+Jbw14WECwasj2E1dQhh mDB/mXLrfnD7iduIeGyRmg2kK6XvKN05dKvWAYB8tuJFOe5Xc79YkK64vLUAm2689Ow9 kuV7RfWbzeDHqUXhrCxMfraLJz+lkOH3r6rsYu6oC5r9mxIf1YhWjEyDsN0GWAXrtiPA ueN0pNIZNz+vUH4wrmrHdKpt9SpsR8hLyIpHTpR4IvxZkmfYNNykv7BiHSPj6CsJEcbi KQ0Q== X-Gm-Message-State: AC+VfDx2d4p20LMlPKLtk5sQV1vW1zsesQKH5r/E/r/T0fNXlTdlFErH iTI1adKT0E2S58uwGr5zBHXgpq8iTm9qgsY= X-Received: from aliceryhl.c.googlers.com ([fda3:e722:ac3:cc00:31:98fb:c0a8:6c8]) (user=aliceryhl job=sendgmr) by 2002:a17:906:847a:b0:969:fc90:bf94 with SMTP id hx26-20020a170906847a00b00969fc90bf94mr9978929ejc.8.1684354116437; Wed, 17 May 2023 13:08:36 -0700 (PDT) Date: Wed, 17 May 2023 20:08:14 +0000 In-Reply-To: <20230517200814.3157916-1-aliceryhl@google.com> Mime-Version: 1.0 References: <20230517200814.3157916-1-aliceryhl@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Message-ID: <20230517200814.3157916-2-aliceryhl@google.com> Subject: [PATCH v1 2/2] rust: sync: implement `AsRef` for `Arc` From: Alice Ryhl To: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor Cc: Boqun Feng , Gary Guo , "=?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?=" , Benno Lossin , Will Deacon , Peter Zijlstra , Mark Rutland , Alice Ryhl , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Wedson Almeida Filho Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED, USER_IN_DEF_DKIM_WL 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 This trait lets you use `Arc` in code that is generic over smart pointer types. The `AsRef` trait should be implemented on all smart pointers. The standard library also implements it on the ordinary `Arc`. Co-developed-by: Wedson Almeida Filho Signed-off-by: Wedson Almeida Filho Signed-off-by: Alice Ryhl --- rust/kernel/sync/arc.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs index 274febe3bb06..9ec911e4a0c7 100644 --- a/rust/kernel/sync/arc.rs +++ b/rust/kernel/sync/arc.rs @@ -264,6 +264,12 @@ impl Deref for Arc { } } +impl AsRef for Arc { + fn as_ref(&self) -> &T { + self.deref() + } +} + impl Clone for Arc { fn clone(&self) -> Self { // INVARIANT: C `refcount_inc` saturates the refcount, so it cannot overflow to zero. -- 2.40.1.606.ga4b1b128d6-goog