pub trait NonEmptyArrayExt<T> {
// Required methods
fn as_nonempty_slice(&self) -> NESlice<'_, T>;
fn nonzero_len(&self) -> NonZeroUsize;
fn into_nonempty_vec(self) -> NEVec<T>;
}
Expand description
Provides extension methods for non-empty arrays.
§Examples
Create a non-empty slice of an array:
assert_eq!(
NESlice::try_from_slice(&[1, 2]),
Some([1, 2].as_nonempty_slice())
);
Get the length of an array as a NonZeroUsize
:
assert_eq!(NonZeroUsize::MIN, [1].nonzero_len());
Convert array into a non-empty vec:
assert_eq!(nev![4], [4].into_nonempty_vec());
Required Methods§
Sourcefn as_nonempty_slice(&self) -> NESlice<'_, T>
fn as_nonempty_slice(&self) -> NESlice<'_, T>
Create a NESlice
that borrows the contents of self
.
Sourcefn nonzero_len(&self) -> NonZeroUsize
fn nonzero_len(&self) -> NonZeroUsize
Returns the length of this array as a NonZeroUsize
.
Sourcefn into_nonempty_vec(self) -> NEVec<T>
fn into_nonempty_vec(self) -> NEVec<T>
Moves self
into a new crate::NEVec
.