about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZachary S <zasample18+github@gmail.com>2024-03-20 17:44:26 -0500
committerZachary S <zasample18+github@gmail.com>2024-03-20 18:25:06 -0500
commit4250216663331fc4efcbd4bb2e5f93caa1b4d2b8 (patch)
treee316d9167a033da8be6e16870114983fc09777c5
parente3df96cfda905301fc8514e000f942222c1ab6ad (diff)
downloadrust-4250216663331fc4efcbd4bb2e5f93caa1b4d2b8.tar.gz
rust-4250216663331fc4efcbd4bb2e5f93caa1b4d2b8.zip
Add `NonNull::<[T]>::is_empty` as insta-stable.
-rw-r--r--library/core/src/ptr/non_null.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs
index 9c0236c172a..8bb87734eb3 100644
--- a/library/core/src/ptr/non_null.rs
+++ b/library/core/src/ptr/non_null.rs
@@ -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!(!slice.is_empty());
+    /// ```
+    #[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