pub struct NonEmptyVec<T> { /* private fields */ }Expand description
A vector type which is guaranteed to be non-empty.
New instances must be created with an initial element to ensure that the
vector is non-empty. This means that the methods first and last always
produce an element of type T.
let v = NonEmptyVec::new(1);
assert_eq!(*v.first(), 1);
assert_eq!(*v.last(), 1);It is possible to push new elements into the vector, but pop will return
None if there is only one element left to ensure that the vector is always
nonempty.
let mut v = NonEmptyVec::new(1);
v.push(2);
assert_eq!(v.pop(), Some(2));
assert_eq!(v.pop(), None);Implementations
sourceimpl<T> NonEmptyVec<T>
impl<T> NonEmptyVec<T>
pub fn new(x: T) -> NonEmptyVec<T>
pub fn first(&self) -> &T
pub fn first_mut(&mut self) -> &mut T
sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Pops the last element of the vector.
This method will return None when there is one element left in the
vector to ensure that the vector remains non-empty.
let mut v = NonEmptyVec::new(1);
v.push(2);
assert_eq!(v.pop(), Some(2));
assert_eq!(v.pop(), None);sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of the vector.
let mut v = NonEmptyVec::new(1);
v.push(2);
v.push(3);
assert_eq!(v.len(), 3);sourcepub fn iter(&self) -> NonEmptyIter<'_, T>ⓘNotable traits for NonEmptyIter<'a, T>impl<'a, T> Iterator for NonEmptyIter<'a, T> type Item = &'a T;
pub fn iter(&self) -> NonEmptyIter<'_, T>ⓘNotable traits for NonEmptyIter<'a, T>impl<'a, T> Iterator for NonEmptyIter<'a, T> type Item = &'a T;
Returns an iterator over the vector.
Trait Implementations
sourceimpl<T: Clone> Clone for NonEmptyVec<T>
impl<T: Clone> Clone for NonEmptyVec<T>
sourcefn clone(&self) -> NonEmptyVec<T>
fn clone(&self) -> NonEmptyVec<T>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl<T: Clone> From<&NonEmptyVec<T>> for Vec<T>
impl<T: Clone> From<&NonEmptyVec<T>> for Vec<T>
sourcefn from(xs: &NonEmptyVec<T>) -> Vec<T>
fn from(xs: &NonEmptyVec<T>) -> Vec<T>
Converts to this type from the input type.
sourceimpl<T> From<NonEmptyVec<T>> for Vec<T>
impl<T> From<NonEmptyVec<T>> for Vec<T>
sourcefn from(xs: NonEmptyVec<T>) -> Vec<T>
fn from(xs: NonEmptyVec<T>) -> Vec<T>
Converts to this type from the input type.
sourceimpl<T> Index<&usize> for NonEmptyVec<T>
impl<T> Index<&usize> for NonEmptyVec<T>
sourceimpl<T> Index<usize> for NonEmptyVec<T>
impl<T> Index<usize> for NonEmptyVec<T>
sourceimpl<T> IndexMut<&usize> for NonEmptyVec<T>
impl<T> IndexMut<&usize> for NonEmptyVec<T>
sourceimpl<T> IndexMut<usize> for NonEmptyVec<T>
impl<T> IndexMut<usize> for NonEmptyVec<T>
sourceimpl<'a, T> IntoIterator for &'a NonEmptyVec<T>
impl<'a, T> IntoIterator for &'a NonEmptyVec<T>
Allows for constructions on the form for t in ts.
sourceimpl<T: PartialEq> PartialEq<NonEmptyVec<T>> for NonEmptyVec<T>
impl<T: PartialEq> PartialEq<NonEmptyVec<T>> for NonEmptyVec<T>
sourcefn eq(&self, other: &NonEmptyVec<T>) -> bool
fn eq(&self, other: &NonEmptyVec<T>) -> bool
This method tests for self and other values to be equal, and is used
by ==. Read more
sourceimpl<T: Clone> TryFrom<&[T]> for NonEmptyVec<T>
impl<T: Clone> TryFrom<&[T]> for NonEmptyVec<T>
sourceimpl<T> TryFrom<Vec<T, Global>> for NonEmptyVec<T>
impl<T> TryFrom<Vec<T, Global>> for NonEmptyVec<T>
impl<T: Eq> Eq for NonEmptyVec<T>
impl<T> StructuralEq for NonEmptyVec<T>
impl<T> StructuralPartialEq for NonEmptyVec<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for NonEmptyVec<T>where
T: RefUnwindSafe,
impl<T> Send for NonEmptyVec<T>where
T: Send,
impl<T> Sync for NonEmptyVec<T>where
T: Sync,
impl<T> Unpin for NonEmptyVec<T>where
T: Unpin,
impl<T> UnwindSafe for NonEmptyVec<T>where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more