pub struct NonEmpty<T> { /* private fields */ }Expand description
A homogeneous sequence with at least one element.
The invariant is enforced at construction boundaries while the storage stays
vector-backed. That keeps recursive AST shapes such as NonEmpty<Expr<P>>
safely indirect, just like Vec<Expr<P>>.
Implementations§
Source§impl<T> NonEmpty<T>
impl<T> NonEmpty<T>
Sourcepub fn new(first: T, rest: Vec<T>) -> Self
pub fn new(first: T, rest: Vec<T>) -> Self
Construct a non-empty sequence from its first item and the remaining items.
Sourcepub fn try_from_vec(items: Vec<T>) -> Result<Self, EmptyVecError>
pub fn try_from_vec(items: Vec<T>) -> Result<Self, EmptyVecError>
Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Mutably borrow as a slice.
Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Returns false; provided for API compatibility with sequence-like code.
Sourcepub fn split_last(&self) -> (&T, &[T])
pub fn split_last(&self) -> (&T, &[T])
Split into the last element and the elements before it.
Trait Implementations§
impl<T: Eq> Eq for NonEmpty<T>
Source§impl<T: FormatEquivalent> FormatEquivalent for NonEmpty<T>
impl<T: FormatEquivalent> FormatEquivalent for NonEmpty<T>
Source§fn format_equivalent(&self, other: &Self) -> bool
fn format_equivalent(&self, other: &Self) -> bool
Returns
true if self and other are equivalent up to formatting.Source§impl<T> IntoIterator for NonEmpty<T>
impl<T> IntoIterator for NonEmpty<T>
Source§impl<'a, T> IntoIterator for &'a NonEmpty<T>
impl<'a, T> IntoIterator for &'a NonEmpty<T>
Source§impl<'a, T> IntoIterator for &'a mut NonEmpty<T>
impl<'a, T> IntoIterator for &'a mut NonEmpty<T>
Source§impl<T: Ord> Ord for NonEmpty<T>
impl<T: Ord> Ord for NonEmpty<T>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: PartialEq> PartialEq for NonEmpty<T>
impl<T: PartialEq> PartialEq for NonEmpty<T>
Source§impl<T: PartialOrd> PartialOrd for NonEmpty<T>
impl<T: PartialOrd> PartialOrd for NonEmpty<T>
impl<T> StructuralPartialEq for NonEmpty<T>
Auto Trait Implementations§
impl<T> Freeze for NonEmpty<T>
impl<T> RefUnwindSafe for NonEmpty<T>where
T: RefUnwindSafe,
impl<T> Send for NonEmpty<T>where
T: Send,
impl<T> Sync for NonEmpty<T>where
T: Sync,
impl<T> Unpin for NonEmpty<T>where
T: Unpin,
impl<T> UnsafeUnpin for NonEmpty<T>
impl<T> UnwindSafe for NonEmpty<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more
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
Compare self to
key and return true if they are equal.