File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -246,6 +246,15 @@ impl<T: ?Sized> Arc<T> {
246246 unsafe { core:: ptr:: addr_of!( ( * ptr) . data) }
247247 }
248248
249+ /// Return a raw pointer to the data in this arc.
250+ pub fn as_ptr ( this : & Self ) -> * const T {
251+ let ptr = this. ptr . as_ptr ( ) ;
252+
253+ // SAFETY: As `ptr` points to a valid allocation of type `ArcInner`,
254+ // field projection to `data`is within bounds of the allocation.
255+ unsafe { core:: ptr:: addr_of!( ( * ptr) . data) }
256+ }
257+
249258 /// Recreates an [`Arc`] instance previously deconstructed via [`Arc::into_raw`].
250259 ///
251260 /// # Safety
@@ -539,11 +548,11 @@ impl<T: ?Sized> ArcBorrow<'_, T> {
539548 }
540549
541550 /// Creates an [`ArcBorrow`] to an [`Arc`] that has previously been deconstructed with
542- /// [`Arc::into_raw`].
551+ /// [`Arc::into_raw`] or [`Arc::as_ptr`] .
543552 ///
544553 /// # Safety
545554 ///
546- /// * The provided pointer must originate from a call to [`Arc::into_raw`].
555+ /// * The provided pointer must originate from a call to [`Arc::into_raw`] or [`Arc::as_ptr`] .
547556 /// * For the duration of the lifetime annotated on this `ArcBorrow`, the reference count must
548557 /// not hit zero.
549558 /// * For the duration of the lifetime annotated on this `ArcBorrow`, there must not be a
You can’t perform that action at this time.
0 commit comments