diff options
| author | Aaron Turon <aturon@mozilla.com> | 2017-03-14 21:10:02 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2017-03-17 13:28:53 -0700 |
| commit | a8f4a1bd984091ffb8f87f9440e2483f94b44a20 (patch) | |
| tree | 09e1c6b160d9151d0b7ec19ef15454a8a531f3ff /src/libcore | |
| parent | 48890d497163bec75d40198b365b3ca670cc3454 (diff) | |
Stabilize rc_raw feature, closes #37197
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/ptr.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index e4ad8cfd256..15174e72795 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -968,12 +968,20 @@ impl<T: ?Sized> Shared<T> { /// # Safety /// /// `ptr` must be non-null. - pub unsafe fn new(ptr: *mut T) -> Self { + pub unsafe fn new(ptr: *const T) -> Self { Shared { pointer: NonZero::new(ptr), _marker: PhantomData } } } #[unstable(feature = "shared", issue = "27730")] +impl<T: ?Sized> Shared<T> { + /// Acquires the underlying pointer as a `*mut` pointer. + pub unsafe fn as_mut_ptr(&self) -> *mut T { + **self as _ + } +} + +#[unstable(feature = "shared", issue = "27730")] impl<T: ?Sized> Clone for Shared<T> { fn clone(&self) -> Self { *self @@ -988,10 +996,10 @@ impl<T: ?Sized, U: ?Sized> CoerceUnsized<Shared<U>> for Shared<T> where T: Unsiz #[unstable(feature = "shared", issue = "27730")] impl<T: ?Sized> Deref for Shared<T> { - type Target = *mut T; + type Target = *const T; #[inline] - fn deref(&self) -> &*mut T { + fn deref(&self) -> &*const T { unsafe { mem::transmute(&*self.pointer) } } } |
