diff options
Diffstat (limited to 'src/libcore/ptr.rs')
| -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) } } } |
