Skip to content

Commit

Permalink
Update more UniquePtr methods to use as_ptr and as_mut_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 25, 2024
1 parent 37a533a commit 8ea95e8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/unique_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ where
///
/// This is the opposite of [std::unique_ptr\<T\>::operator bool](https://en.cppreference.com/w/cpp/memory/unique_ptr/operator_bool).
pub fn is_null(&self) -> bool {
let ptr = unsafe { T::__get(self.repr) };
ptr.is_null()
self.as_ptr().is_null()
}

/// Returns a reference to the object owned by this UniquePtr if any,
Expand All @@ -69,8 +68,9 @@ where
/// Returns a mutable pinned reference to the object owned by this UniquePtr
/// if any, otherwise None.
pub fn as_mut(&mut self) -> Option<Pin<&mut T>> {
let ptr = self.as_mut_ptr();
unsafe {
let mut_reference = (T::__get(self.repr) as *mut T).as_mut()?;
let mut_reference = ptr.as_mut()?;
Some(Pin::new_unchecked(mut_reference))
}
}
Expand Down

0 comments on commit 8ea95e8

Please sign in to comment.