1 //! See [`NonEmptyVec`].
3 /// A [`Vec`] that is guaranteed to at least contain one element.
4 pub struct NonEmptyVec
<T
> {
9 impl<T
> NonEmptyVec
<T
> {
11 pub fn new(first
: T
) -> Self {
12 NonEmptyVec { first, rest: Vec::new() }
16 pub fn last_mut(&mut self) -> &mut T
{
17 self.rest
.last_mut().unwrap_or(&mut self.first
)
21 pub fn pop(&mut self) -> Option
<T
> {
26 pub fn push(&mut self, value
: T
) {
31 pub fn len(&self) -> usize {
36 pub fn into_last(mut self) -> T
{
37 self.rest
.pop().unwrap_or(self.first
)