From: Alice Ryhl Date: Wed, 17 May 2023 20:08:14 +0000 (+0000) Subject: rust: sync: implement `AsRef` for `Arc` X-Git-Tag: microblaze-v6.6~252^2~5 X-Git-Url: http://git.monstr.eu/?a=commitdiff_plain;h=47329ba14b5aac1ac975544eee71ecc888557d23;p=linux-2.6-microblaze.git 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 --- 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.