]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rust: sync: add `UniqueArc::as_ptr`
authorAndreas Hindborg <a.hindborg@kernel.org>
Fri, 5 Jun 2026 13:16:48 +0000 (15:16 +0200)
committerMiguel Ojeda <ojeda@kernel.org>
Tue, 9 Jun 2026 02:13:21 +0000 (04:13 +0200)
Add an associated function to `UniqueArc` for getting a raw pointer. The
implementation defers to the `Arc` implementation.

Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://patch.msgid.link/20260605-unique-arc-as-ptr-v2-1-425476d2abdb@kernel.org
[ Relaxed bound moving it to new `T: ?Sized` impl block. Reworded since
  it is not a method anymore. Added intra-doc link. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/kernel/sync/arc.rs

index feca07e8d13d1b37cba83d788d8b496795bc17b2..5ac4961b7cd20e3a393d19c10a362934b166c53d 100644 (file)
@@ -760,6 +760,14 @@ impl<T> UniqueArc<T> {
     }
 }
 
+impl<T: ?Sized> UniqueArc<T> {
+    /// Return a raw pointer to the data in this [`UniqueArc`].
+    #[inline]
+    pub fn as_ptr(this: &Self) -> *const T {
+        Arc::as_ptr(&this.inner)
+    }
+}
+
 impl<T> UniqueArc<MaybeUninit<T>> {
     /// Converts a `UniqueArc<MaybeUninit<T>>` into a `UniqueArc<T>` by writing a value into it.
     pub fn write(mut self, value: T) -> UniqueArc<T> {