Skip to content

Commit

Permalink
Add NonNull::<[T]>::is_empty as insta-stable.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachs18 committed Mar 20, 2024
1 parent e3df96c commit 43d4124
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions library/core/src/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,27 @@ impl<T> NonNull<[T]> {
self.as_ptr().len()
}

/// Returns `true` if the non-null raw slice has a length of 0.
///
/// # Examples
///
/// ```rust
/// use std::ptr::NonNull;
///
/// let slice: NonNull<[i8]> = NonNull::slice_from_raw_parts(NonNull::dangling(), 3);
/// assert_eq!(!slice.is_empty());

Check failure on line 1586 in library/core/src/ptr/non_null.rs

View workflow job for this annotation

GitHub Actions / PR - mingw-check

unexpected end of macro invocation
/// ```
#[stable(feature = "slice_ptr_is_empty_nonnull", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(
feature = "const_slice_ptr_is_empty_nonnull",
since = "CURRENT_RUSTC_VERSION"
)]
#[must_use]
#[inline]
pub const fn is_empty(self) -> bool {
self.len() == 0
}

/// Returns a non-null pointer to the slice's buffer.
///
/// # Examples
Expand Down

0 comments on commit 43d4124

Please sign in to comment.