diff --git a/src/shared_ptr.rs b/src/shared_ptr.rs index 6aa68c0c3..cb37c2ab1 100644 --- a/src/shared_ptr.rs +++ b/src/shared_ptr.rs @@ -50,12 +50,12 @@ where /// Create a shared pointer from an already-allocated object /// Corresponds to constructor (3) of [std::shared\_ptr](https://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr) - /// + /// /// The SharedPtr gains ownership of the pointer and will call std::default_delete on it when the refcount goes to zero. /// The data will not be moved, so any pointers to this data elsewhere in the program continue to be valid - /// + /// /// # Safety - /// + /// /// Value must either be null or point to a valid instance of T pub unsafe fn from_unmanaged(value: *mut T) -> Self { let mut shared_ptr = MaybeUninit::>::uninit(); diff --git a/src/unique_ptr.rs b/src/unique_ptr.rs index ff949b6c5..4d68e4ab2 100644 --- a/src/unique_ptr.rs +++ b/src/unique_ptr.rs @@ -108,17 +108,18 @@ where ty: PhantomData, } } +} +impl UniquePtr +where + T: UniquePtrTarget + SharedPtrTarget, +{ /// Convert this UniquePtr to a SharedPtr, analogous to constructor (13) for [std::shared\_ptr](https://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr) - pub fn to_shared(self) -> SharedPtr where T: SharedPtrTarget { + pub fn to_shared(self) -> SharedPtr { unsafe { SharedPtr::from_unmanaged(self.into_raw()) } } } -impl UniquePtr -where T: UniquePtrTarget + SharedPtrTarget { -} - unsafe impl Send for UniquePtr where T: Send + UniquePtrTarget {} unsafe impl Sync for UniquePtr where T: Sync + UniquePtrTarget {} @@ -239,7 +240,6 @@ pub unsafe trait UniquePtrTarget { unsafe fn __release(repr: MaybeUninit<*mut c_void>) -> *mut Self; #[doc(hidden)] unsafe fn __drop(repr: MaybeUninit<*mut c_void>); - } extern "C" {