diff options
author | Alice Ryhl <aliceryhl@google.com> | 2023-05-17 20:08:14 +0000 |
---|---|---|
committer | Miguel Ojeda <ojeda@kernel.org> | 2023-05-31 18:53:10 +0200 |
commit | 47329ba14b5aac1ac975544eee71ecc888557d23 (patch) | |
tree | 2f643c9685a471d7a2b4c4d8738772cdc4a35470 /rust | |
parent | bd780aea671eda9660837c05d9ba58de22ceecad (diff) | |
download | linux-47329ba14b5aac1ac975544eee71ecc888557d23.tar.gz linux-47329ba14b5aac1ac975544eee71ecc888557d23.tar.bz2 linux-47329ba14b5aac1ac975544eee71ecc888557d23.zip |
rust: sync: implement `AsRef<T>` for `Arc<T>`
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: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com>
Link: https://lore.kernel.org/r/20230517200814.3157916-2-aliceryhl@google.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust')
-rw-r--r-- | rust/kernel/sync/arc.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs index b03d84f7ce87..ace478442998 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. |