From 47329ba14b5aac1ac975544eee71ecc888557d23 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Wed, 17 May 2023 20:08:14 +0000 Subject: rust: sync: implement `AsRef` for `Arc` 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 Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Benno Lossin Reviewed-by: Gary Guo Reviewed-by: Andreas Hindborg Link: https://lore.kernel.org/r/20230517200814.3157916-2-aliceryhl@google.com Signed-off-by: Miguel Ojeda --- 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 b03d84f7ce87..ace478442998 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. -- cgit v1.2.3-70-g09d2