From: Gary Guo <gary@garyguo.net>
To: Alice Ryhl <aliceryhl@google.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Will Deacon" <will@kernel.org>,
"Peter Zijlstra" <peterz@infradead.org>,
"Mark Rutland" <mark.rutland@arm.com>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
patches@lists.linux.dev,
"Wedson Almeida Filho" <walmeida@microsoft.com>
Subject: Re: [PATCH v1 2/2] rust: sync: implement `AsRef<T>` for `Arc<T>`
Date: Tue, 23 May 2023 17:01:14 +0100 [thread overview]
Message-ID: <20230523170114.0e4e12c8.gary@garyguo.net> (raw)
In-Reply-To: <20230517200814.3157916-2-aliceryhl@google.com>
On Wed, 17 May 2023 20:08:14 +0000
Alice Ryhl <aliceryhl@google.com> wrote:
> This trait lets you use `Arc<T>` 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 <walmeida@microsoft.com>
> Signed-off-by: Wedson Almeida Filho <walmeida@microsoft.com>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
> ---
> 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<T: ?Sized> Deref for Arc<T> {
> }
> }
>
> +impl<T: ?Sized> AsRef<T> for Arc<T> {
> + fn as_ref(&self) -> &T {
> + self.deref()
> + }
> +}
> +
> impl<T: ?Sized> Clone for Arc<T> {
> fn clone(&self) -> Self {
> // INVARIANT: C `refcount_inc` saturates the refcount, so it cannot overflow to zero.
next prev parent reply other threads:[~2023-05-23 16:01 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-17 20:08 [PATCH v1 1/2] rust: sync: add `Arc::ptr_eq` Alice Ryhl
2023-05-17 20:08 ` [PATCH v1 2/2] rust: sync: implement `AsRef<T>` for `Arc<T>` Alice Ryhl
2023-05-17 20:42 ` Martin Rodriguez Reboredo
2023-05-23 11:59 ` Andreas Hindborg
2023-05-23 16:01 ` Gary Guo [this message]
2023-05-25 13:50 ` Benno Lossin
2023-05-17 20:41 ` [PATCH v1 1/2] rust: sync: add `Arc::ptr_eq` Martin Rodriguez Reboredo
2023-05-23 11:54 ` Andreas Hindborg
2023-05-23 16:00 ` Gary Guo
2023-05-25 13:50 ` Benno Lossin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230523170114.0e4e12c8.gary@garyguo.net \
--to=gary@garyguo.net \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=ojeda@kernel.org \
--cc=patches@lists.linux.dev \
--cc=peterz@infradead.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=walmeida@microsoft.com \
--cc=wedsonaf@gmail.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.