Struct texcraft_stdext::collections::nevec::Nevec
source · pub struct Nevec<T> { /* private fields */ }
Expand description
Non-empty vector type.
Implementations§
source§impl<T> Nevec<T>
impl<T> Nevec<T>
sourcepub fn with_capacity(first: T, capacity: usize) -> Nevec<T>
pub fn with_capacity(first: T, capacity: usize) -> Nevec<T>
Creates a new Nevec
with the provided first element and initial capacity.
sourcepub fn new_with_tail(first: T, tail: Vec<T>) -> Nevec<T>
pub fn new_with_tail(first: T, tail: Vec<T>) -> Nevec<T>
Creates a new Nevec
with the provided first element and remaining elements (“the tail”).
sourcepub fn last(&self) -> &T
pub fn last(&self) -> &T
Gets a reference to the last element of the vector. Because the vector is guaranteed to be non-empty, this will always succeed.
sourcepub fn last_mut(&mut self) -> &mut T
pub fn last_mut(&mut self) -> &mut T
Gets a mutable reference to the last element of the vector. Because the vector is guaranteed to be non-empty, this will always succeed.
sourcepub fn pop(self) -> T
pub fn pop(self) -> T
Pops an element from the end of the vector.
Because the vector is guaranteed to be non-empty, this will always succeed. However if the vector has only 1 element, then after popping it will no longer be non-empty. For this reason, the pop method takes ownership of the vector, and destroys it in the process.
In the case when the vector has more than 1 element, the method pop_from_tail
can be used to retrieve the last element without destroying the vector.
sourcepub fn pop_from_tail(&mut self) -> Option<T>
pub fn pop_from_tail(&mut self) -> Option<T>
Pops an element from the tail of the vector; that is, the part of the vector after the first element.
Returns None
if and only if the vector has exactly 1 element. In this
case the method pop
is needed to take ownership of the element.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of the vector, which is guaranteed to be at least 1.