pub struct NESlice<'a, T> { /* private fields */ }Expand description
A non-empty slice. Like crate::NEVec, but guaranteed to have borrowed
contents.
NESlice::try_from_slice is the simplest way to construct this from
borrowed data.
Unfortunately there is no macro for this, but if you want one, just use
nev! and handle the ownership manually. Also consider
crate::NEVec::as_nonempty_slice.
If you want access to the inner slice, use AsRef.
Implementations§
Source§impl<'a, T> NESlice<'a, T>
impl<'a, T> NESlice<'a, T>
Sourcepub const fn try_from_slice(slice: &'a [T]) -> Option<Self>
pub const fn try_from_slice(slice: &'a [T]) -> Option<Self>
Using try_from_slice gives a proof that the input slice is non-empty
in the Some branch.
Sourcepub fn len(&self) -> NonZeroUsize
pub fn len(&self) -> NonZeroUsize
Get the length of the slice.
Sourcepub const fn is_empty(&self) -> bool
👎Deprecated: A NESlice is never empty.
pub const fn is_empty(&self) -> bool
No, this slice is not empty.
Sourcepub fn iter(&self) -> Iter<'_, T>
pub fn iter(&self) -> Iter<'_, T>
Returns a regular iterator over the values in this non-empty slice.
For a NonEmptyIterator see Self::nonempty_iter().
Sourcepub fn nonempty_iter(&self) -> Iter<'_, T>
pub fn nonempty_iter(&self) -> Iter<'_, T>
Returns a non-empty iterator.
Sourcepub fn nonempty_chunks(&'a self, chunk_size: NonZeroUsize) -> NEChunks<'a, T>
pub fn nonempty_chunks(&'a self, chunk_size: NonZeroUsize) -> NEChunks<'a, T>
Returns a non-empty iterator over chunk_size elements of the NESlice
at a time, starting at the beginning of the NESlice.
use std::num::NonZeroUsize;
use nonempty_collections::*;
let v = nev![1, 2, 3, 4, 5, 6];
let s = v.as_nonempty_slice();
let n = NonZeroUsize::new(2).unwrap();
let r = s.nonempty_chunks(n).collect::<NEVec<_>>();
let a = nev![1, 2];
let b = nev![3, 4];
let c = nev![5, 6];
assert_eq!(
r,
nev![
a.as_nonempty_slice(),
b.as_nonempty_slice(),
c.as_nonempty_slice()
]
);Trait Implementations§
Source§impl<'a, T> IntoIterator for &'a NESlice<'a, T>
impl<'a, T> IntoIterator for &'a NESlice<'a, T>
Source§impl<'a, T> IntoIterator for NESlice<'a, T>
impl<'a, T> IntoIterator for NESlice<'a, T>
Source§impl<'a, T> IntoNonEmptyIterator for &'a NESlice<'a, T>
impl<'a, T> IntoNonEmptyIterator for &'a NESlice<'a, T>
Source§type IntoNEIter = Iter<'a, T>
type IntoNEIter = Iter<'a, T>
NonEmptyIterator are we turning this into?Source§fn into_nonempty_iter(self) -> Self::IntoNEIter
fn into_nonempty_iter(self) -> Self::IntoNEIter
NonEmptyIterator from a value.Source§impl<'a, T> IntoNonEmptyIterator for NESlice<'a, T>
impl<'a, T> IntoNonEmptyIterator for NESlice<'a, T>
Source§type IntoNEIter = Iter<'a, T>
type IntoNEIter = Iter<'a, T>
NonEmptyIterator are we turning this into?Source§fn into_nonempty_iter(self) -> Self::IntoNEIter
fn into_nonempty_iter(self) -> Self::IntoNEIter
NonEmptyIterator from a value.Source§impl<'a, T: Ord> Ord for NESlice<'a, T>
impl<'a, T: Ord> Ord for NESlice<'a, T>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<'a, T: PartialOrd> PartialOrd for NESlice<'a, T>
impl<'a, T: PartialOrd> PartialOrd for NESlice<'a, T>
impl<'a, T: Eq> Eq for NESlice<'a, T>
impl<'a, T> StructuralPartialEq for NESlice<'a, T>
Auto Trait Implementations§
impl<'a, T> Freeze for NESlice<'a, T>
impl<'a, T> RefUnwindSafe for NESlice<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for NESlice<'a, T>where
T: Sync,
impl<'a, T> Sync for NESlice<'a, T>where
T: Sync,
impl<'a, T> Unpin for NESlice<'a, T>
impl<'a, T> UnwindSafe for NESlice<'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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoIteratorExt for Twhere
T: IntoIterator,
impl<T> IntoIteratorExt for Twhere
T: IntoIterator,
Source§fn try_into_nonempty_iter(self) -> Option<<T as IntoIteratorExt>::IntoIter>
fn try_into_nonempty_iter(self) -> Option<<T as IntoIteratorExt>::IntoIter>
Converts self into a non-empty iterator or returns None if
the iterator is empty.
Source§type Item = <T as IntoIterator>::Item
type Item = <T as IntoIterator>::Item
Source§type IntoIter = NonEmptyIterAdapter<Peekable<<T as IntoIterator>::IntoIter>>
type IntoIter = NonEmptyIterAdapter<Peekable<<T as IntoIterator>::IntoIter>>
NonEmptyIterator are we turning this into?