Skip to content

Commit 43d4124

Browse files
committed
Add NonNull::<[T]>::is_empty as insta-stable.
1 parent e3df96c commit 43d4124

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

library/core/src/ptr/non_null.rs

+21
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,27 @@ impl<T> NonNull<[T]> {
15751575
self.as_ptr().len()
15761576
}
15771577

1578+
/// Returns `true` if the non-null raw slice has a length of 0.
1579+
///
1580+
/// # Examples
1581+
///
1582+
/// ```rust
1583+
/// use std::ptr::NonNull;
1584+
///
1585+
/// let slice: NonNull<[i8]> = NonNull::slice_from_raw_parts(NonNull::dangling(), 3);
1586+
/// assert_eq!(!slice.is_empty());
1587+
/// ```
1588+
#[stable(feature = "slice_ptr_is_empty_nonnull", since = "CURRENT_RUSTC_VERSION")]
1589+
#[rustc_const_stable(
1590+
feature = "const_slice_ptr_is_empty_nonnull",
1591+
since = "CURRENT_RUSTC_VERSION"
1592+
)]
1593+
#[must_use]
1594+
#[inline]
1595+
pub const fn is_empty(self) -> bool {
1596+
self.len() == 0
1597+
}
1598+
15781599
/// Returns a non-null pointer to the slice's buffer.
15791600
///
15801601
/// # Examples

0 commit comments

Comments
 (0)