[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <DT_8UBvti_dML0vOrXVfUwNnTjhHlhBsioFDBIudjzzxjJl1SCTHU6cn5qjmZj3wTt7r8R1PFDStDv2C2IAjMj4Ubbpy5r587LkyfJEa4VY=@proton.me>
Date: Thu, 25 May 2023 13:50:57 +0000
From: Benno Lossin <benno.lossin@...ton.me>
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: Miguel Ojeda <ojeda@...nel.org>,
Wedson Almeida Filho <wedsonaf@...il.com>,
Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Will Deacon <will@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Mark Rutland <mark.rutland@....com>,
rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
patches@...ts.linux.dev,
Wedson Almeida Filho <walmeida@...rosoft.com>
Subject: Re: [PATCH v1 2/2] rust: sync: implement `AsRef<T>` for `Arc<T>`
On 5/17/23 22:08, Alice Ryhl 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@...rosoft.com>
> Signed-off-by: Wedson Almeida Filho <walmeida@...rosoft.com>
> Signed-off-by: Alice Ryhl <aliceryhl@...gle.com>
Reviewed-by: Benno Lossin <benno.lossin@...ton.me>
> ---
> 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.
> --
> 2.40.1.606.ga4b1b128d6-goog
>
--
Cheers,
Benno
Powered by blists - more mailing lists