Skip to content

Commit a816267

Browse files
committed
also add is_empty to const raw slices
1 parent eab8c7d commit a816267

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

Diff for: library/core/src/ptr/const_ptr.rs

+18
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,24 @@ impl<T> *const [T] {
16441644
metadata(self)
16451645
}
16461646

1647+
/// Returns `true` if the raw slice has a length of 0.
1648+
///
1649+
/// # Examples
1650+
///
1651+
/// ```
1652+
/// #![feature(slice_ptr_len)]
1653+
/// use std::ptr;
1654+
///
1655+
/// let slice: *const [i8] = ptr::slice_from_raw_parts(ptr::null(), 3);
1656+
/// assert!(!slice.is_empty());
1657+
/// ```
1658+
#[inline(always)]
1659+
#[unstable(feature = "slice_ptr_len", issue = "71146")]
1660+
#[rustc_const_unstable(feature = "const_slice_ptr_len", issue = "71146")]
1661+
pub const fn is_empty(self) -> bool {
1662+
self.len() == 0
1663+
}
1664+
16471665
/// Returns a raw pointer to the slice's buffer.
16481666
///
16491667
/// This is equivalent to casting `self` to `*const T`, but more type-safe.

Diff for: library/core/src/ptr/mut_ptr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1920,10 +1920,10 @@ impl<T> *mut [T] {
19201920
///
19211921
/// ```
19221922
/// #![feature(slice_ptr_len)]
1923+
/// use std::ptr;
19231924
///
1924-
/// let mut a = [1, 2, 3];
1925-
/// let ptr = &mut a as *mut [_];
1926-
/// assert!(!ptr.is_empty());
1925+
/// let slice: *mut [i8] = ptr::slice_from_raw_parts_mut(ptr::null_mut(), 3);
1926+
/// assert!(!slice.is_empty());
19271927
/// ```
19281928
#[inline(always)]
19291929
#[unstable(feature = "slice_ptr_len", issue = "71146")]

0 commit comments

Comments
 (0)