pub struct NEVec<T>(/* private fields */);Expand description
Non-empty vector type.
Implementations§
Source§impl<T> NEVec<T>
impl<T> NEVec<T>
Sourcepub fn new(head: T, tail: Vec<T>) -> Self
pub fn new(head: T, tail: Vec<T>) -> Self
Creates a new NEVec, ensuring at least one element is present.
Sourcepub fn singleton(value: T) -> Self
pub fn singleton(value: T) -> Self
Creates a new singleton NEVec. Semantically equivalent to:
NEVec::new(value, Vec::new());Sourcepub fn head(&self) -> &T
pub fn head(&self) -> &T
Returns the first element. This operation is safe as the invariant guarantees at least one element is present.
Sourcepub fn init(&self) -> Iter<'_, T>
pub fn init(&self) -> Iter<'_, T>
Returns all elements except the last one. This may be empty if the NEVec is a singleton.
Sourcepub fn tail(&self) -> Iter<'_, T>
pub fn tail(&self) -> Iter<'_, T>
Returns all elements except the first one. This may be empty if the NEVec is a singleton.
Sourcepub fn last(&self) -> &T
pub fn last(&self) -> &T
Returns the last element. This operation is safe as the invariant guarantees at least one element is present.
Sourcepub fn from_deque(deque: VecDeque<T>) -> Result<Self, NonEmptyError>
pub fn from_deque(deque: VecDeque<T>) -> Result<Self, NonEmptyError>
Sourcepub fn push_front(&mut self, value: T)
pub fn push_front(&mut self, value: T)
Pushes an element to the front of the NEVec.
Sourcepub fn split_first(&self) -> (&T, Iter<'_, T>)
pub fn split_first(&self) -> (&T, Iter<'_, T>)
Splits the NEVec into the first element and the rest. This operation is guaranteed to succeed because the invariant guarantees at least one element is present.
Sourcepub fn split_last(&self) -> (Iter<'_, T>, &T)
pub fn split_last(&self) -> (Iter<'_, T>, &T)
Splits the NEVec into all elements except the last one and the last element. This operation is guaranteed to succeed because the invariant guarantees at least one element is present.
Sourcepub fn take_split_first(self) -> (T, IntoIter<T>)
pub fn take_split_first(self) -> (T, IntoIter<T>)
Like NEVec::split_first, but consumes the NEVec.
Sourcepub fn take_split_last(self) -> (IntoIter<T>, T)
pub fn take_split_last(self) -> (IntoIter<T>, T)
Like NEVec::split_last, but consumes the NEVec.
Sourcepub fn extend<I: IntoIterator<Item = T>>(&mut self, other: I)
pub fn extend<I: IntoIterator<Item = T>>(&mut self, other: I)
Extends the NEVec with the elements from another collection.