diff --git a/src/unique_ptr.rs b/src/unique_ptr.rs index 5f8019586..1366e7592 100644 --- a/src/unique_ptr.rs +++ b/src/unique_ptr.rs @@ -90,8 +90,8 @@ where } } - /// Returns a pointer to the object owned by this UniquePtr - /// if any, otherwise the null pointer. + /// Returns a raw const pointer to the object owned by this UniquePtr if + /// any, otherwise the null pointer. pub fn as_ptr(&self) -> *const T { match self.as_ref() { Some(target) => target as *const T, @@ -99,13 +99,13 @@ where } } - /// Returns a mutable pointer to the object owned by this UniquePtr - /// if any, otherwise the null pointer. + /// Returns a raw mutable pointer to the object owned by this UniquePtr if + /// any, otherwise the null pointer. /// /// As with [std::unique_ptr\::get](https://en.cppreference.com/w/cpp/memory/unique_ptr/get), - /// this doesn't require that you hold a mutable reference to the `UniquePtr`. - /// This differs from Rust norms, so extra care should be taken in - /// the way the pointer is used. + /// this doesn't require that you hold an exclusive reference to the + /// UniquePtr. This differs from Rust norms, so extra care should be taken + /// in the way the pointer is used. pub fn as_mut_ptr(&self) -> *mut T { self.as_ptr() as *mut T } diff --git a/tests/test.rs b/tests/test.rs index 6d9ba34c1..df0610491 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -259,8 +259,8 @@ fn test_c_method_calls() { assert_eq!(2021, unique_ptr.get()); assert_eq!(2021, unique_ptr.get2()); assert_eq!(2021, *unique_ptr.getRef()); - assert_eq!(2021, unsafe { unique_ptr.as_mut_ptr().as_ref() }.unwrap().get()); - assert_eq!(2021, unsafe { unique_ptr.as_ptr().as_ref() }.unwrap().get()); + assert_eq!(2021, unsafe { &mut *unique_ptr.as_mut_ptr() }.get()); + assert_eq!(2021, unsafe { &*unique_ptr.as_ptr() }.get()); assert_eq!(2021, *unique_ptr.pin_mut().getMut()); assert_eq!(2022, unique_ptr.pin_mut().set_succeed(2022).unwrap()); assert!(unique_ptr.pin_mut().get_fail().is_err());