From: Wedson Almeida Filho Date: Wed, 28 Dec 2022 06:03:44 +0000 (+0000) Subject: rust: sync: allow type of `self` to be `ArcBorrow` X-Git-Tag: v6.6.17~5570^2~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=92a655ae00a2f15fdd80eb96cd23526c0d8f0bfd;p=platform%2Fkernel%2Flinux-rpi.git rust: sync: allow type of `self` to be `ArcBorrow` This allows associated functions whose `self` argument has `ArcBorrow` as their type. This, in turn, allows callers to use the dot syntax to make calls. Signed-off-by: Wedson Almeida Filho Reviewed-by: Alice Ryhl Reviewed-by: Gary Guo Reviewed-by: Vincenzo Palazzo Acked-by: Boqun Feng Signed-off-by: Miguel Ojeda --- diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs index f68bfc0..84f31c8 100644 --- a/rust/kernel/sync/arc.rs +++ b/rust/kernel/sync/arc.rs @@ -255,11 +255,34 @@ impl Drop for Arc { /// // Assert that both `obj` and `cloned` point to the same underlying object. /// assert!(core::ptr::eq(&*obj, &*cloned)); /// ``` +/// +/// Using `ArcBorrow` as the type of `self`: +/// +/// ``` +/// use crate::sync::{Arc, ArcBorrow}; +/// +/// struct Example { +/// a: u32, +/// b: u32, +/// } +/// +/// impl Example { +/// fn use_reference(self: ArcBorrow<'_, Self>) { +/// // ... +/// } +/// } +/// +/// let obj = Arc::try_new(Example { a: 10, b: 20 })?; +/// obj.as_arc_borrow().use_reference(); +/// ``` pub struct ArcBorrow<'a, T: ?Sized + 'a> { inner: NonNull>, _p: PhantomData<&'a ()>, } +// This is to allow [`ArcBorrow`] (and variants) to be used as the type of `self`. +impl core::ops::Receiver for ArcBorrow<'_, T> {} + impl Clone for ArcBorrow<'_, T> { fn clone(&self) -> Self { *self