Skip to content

Commit 47329ba

Browse files
Darksonnojeda
authored andcommitted
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 <[email protected]> Signed-off-by: Wedson Almeida Filho <[email protected]> Signed-off-by: Alice Ryhl <[email protected]> Reviewed-by: Martin Rodriguez Reboredo <[email protected]> Reviewed-by: Benno Lossin <[email protected]> Reviewed-by: Gary Guo <[email protected]> Reviewed-by: Andreas Hindborg <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent bd780ae commit 47329ba

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

rust/kernel/sync/arc.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,12 @@ impl<T: ?Sized> Deref for Arc<T> {
264264
}
265265
}
266266

267+
impl<T: ?Sized> AsRef<T> for Arc<T> {
268+
fn as_ref(&self) -> &T {
269+
self.deref()
270+
}
271+
}
272+
267273
impl<T: ?Sized> Clone for Arc<T> {
268274
fn clone(&self) -> Self {
269275
// INVARIANT: C `refcount_inc` saturates the refcount, so it cannot overflow to zero.

0 commit comments

Comments
 (0)