pub struct NonEmptySlice<'a, T: Sized> { /* private fields */ }
Expand description
A non-empty slice type, counterpart of &[T]
.
Implementations§
Source§impl<'a, T: Sized> NonEmptySlice<'a, T>
impl<'a, T: Sized> NonEmptySlice<'a, T>
Sourcepub fn from_slice(slice: &'a [T]) -> Self
pub fn from_slice(slice: &'a [T]) -> Self
Converts a &[T]
into a NonEmptySlice
.
§Panics
This function will panic if the passed slice is empty.
Sourcepub const fn from_slice_checked(slice: &'a [T]) -> Option<Self>
pub const fn from_slice_checked(slice: &'a [T]) -> Option<Self>
Converts a &[T]
into a NonEmptySlice
.
Returns None
if the passed slice is empty.
Sourcepub const fn len(&self) -> NonZeroUsize
pub const fn len(&self) -> NonZeroUsize
Returns the number of elements in the slice.
Sourcepub fn first(&self) -> &T
pub fn first(&self) -> &T
Returns the first element of the slice.
let s = NonEmptySlice::from_slice(&[10, 40, 30]);
assert_eq!(s.first(), &10);
Sourcepub fn last(&self) -> &T
pub fn last(&self) -> &T
Returns the last element of the slice.
let s = NonEmptySlice::from_slice(&[10, 40, 30]);
assert_eq!(s.last(), &30);
Sourcepub fn split_first(&self) -> (&T, &[T])
pub fn split_first(&self) -> (&T, &[T])
Returns the first and all the rest of the elements of the slice.
let s = NonEmptySlice::from_slice(&[10, 40, 30]);
assert_eq!(s.split_first(), (&10, &[40, 30][..]));
Sourcepub fn split_last(&self) -> (&T, &[T])
pub fn split_last(&self) -> (&T, &[T])
Returns the last and all the rest of the elements of the slice.
let s = NonEmptySlice::from_slice(&[10, 40, 30]);
assert_eq!(s.split_last(), (&30, &[10, 40][..]));
Trait Implementations§
Source§impl<'a, T> AsRef<[T]> for NonEmptySlice<'a, T>
impl<'a, T> AsRef<[T]> for NonEmptySlice<'a, T>
Source§impl<'a, T: Clone> Clone for NonEmptySlice<'a, T>
impl<'a, T: Clone> Clone for NonEmptySlice<'a, T>
Source§impl<'a, T: Ord> Ord for NonEmptySlice<'a, T>
impl<'a, T: Ord> Ord for NonEmptySlice<'a, T>
Source§impl<'a, T: PartialEq> PartialEq for NonEmptySlice<'a, T>
impl<'a, T: PartialEq> PartialEq for NonEmptySlice<'a, T>
Source§impl<'a, T: PartialOrd> PartialOrd for NonEmptySlice<'a, T>
impl<'a, T: PartialOrd> PartialOrd for NonEmptySlice<'a, T>
impl<'a, T: Copy> Copy for NonEmptySlice<'a, T>
impl<'a, T: Eq> Eq for NonEmptySlice<'a, T>
Auto Trait Implementations§
impl<'a, T> Freeze for NonEmptySlice<'a, T>
impl<'a, T> RefUnwindSafe for NonEmptySlice<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for NonEmptySlice<'a, T>where
T: Sync,
impl<'a, T> Sync for NonEmptySlice<'a, T>where
T: Sync,
impl<'a, T> Unpin for NonEmptySlice<'a, T>
impl<'a, T> UnwindSafe for NonEmptySlice<'a, T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more