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> {
246
246
unsafe { core:: ptr:: addr_of!( ( * ptr) . data) }
247
247
}
248
248
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
+
249
258
/// Recreates an [`Arc`] instance previously deconstructed via [`Arc::into_raw`].
250
259
///
251
260
/// # Safety
@@ -539,11 +548,11 @@ impl<T: ?Sized> ArcBorrow<'_, T> {
539
548
}
540
549
541
550
/// Creates an [`ArcBorrow`] to an [`Arc`] that has previously been deconstructed with
542
- /// [`Arc::into_raw`].
551
+ /// [`Arc::into_raw`] or [`Arc::as_ptr`] .
543
552
///
544
553
/// # Safety
545
554
///
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`] .
547
556
/// * For the duration of the lifetime annotated on this `ArcBorrow`, the reference count must
548
557
/// not hit zero.
549
558
/// * 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