From f03d50568b05934348ceaef2ff792e9e16643d95 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Sat, 18 Feb 2023 11:12:57 -0600 Subject: [PATCH] clean up safety docs --- src/shared_ptr.rs | 8 +++++--- src/unique_ptr.rs | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/shared_ptr.rs b/src/shared_ptr.rs index cb37c2ab1..6d45be610 100644 --- a/src/shared_ptr.rs +++ b/src/shared_ptr.rs @@ -49,14 +49,16 @@ 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) + /// 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 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 + /// * Value must either be null or point to a valid instance of T + /// * Value must not be deleted (as the `std::shared_ptr` now manages its lifetime) + /// * Value must not be accessed after the last `std::shared_ptr` is dropped pub unsafe fn from_unmanaged(value: *mut T) -> Self { let mut shared_ptr = MaybeUninit::>::uninit(); let new = shared_ptr.as_mut_ptr().cast(); diff --git a/src/unique_ptr.rs b/src/unique_ptr.rs index 4d68e4ab2..570264a38 100644 --- a/src/unique_ptr.rs +++ b/src/unique_ptr.rs @@ -114,7 +114,7 @@ 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) + /// 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 { unsafe { SharedPtr::from_unmanaged(self.into_raw()) } }