Skip to content

Commit

Permalink
Add Id::retain_null helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Jan 6, 2022
1 parent ee4d475 commit 8f5b8a0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions objc2/src/rc/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,21 @@ impl<T: Message, O: Ownership> Id<T, O> {
unsafe { Self::new(res) }
}

/// Retains an object pointer that may be null.
///
/// This is just a convenience wrapper over [`Id::retain`] so that you
/// don't need to construct a [`NonNull`] when you know the pointer may
/// be null.
///
/// # Safety
///
/// Same as [`Id::retain`].
#[inline]
pub unsafe fn retain_null(ptr: *mut T) -> Option<Id<T, O>> {
// SAFETY: Upheld by the caller
NonNull::new(ptr).map(|ptr| unsafe { Id::retain(ptr) })
}

#[cfg_attr(not(debug_assertions), inline)]
fn autorelease_inner(self) -> *mut T {
// Note that this (and the actual `autorelease`) is not an associated
Expand Down

0 comments on commit 8f5b8a0

Please sign in to comment.