[−][src]Struct nonempty::NonEmpty
Methods
impl<T> NonEmpty<T>
[src]
pub const fn new(e: T) -> Self
[src]
Alias for NonEmpty::singleton
.
pub const fn singleton(e: T) -> Self
[src]
Create a new non-empty list with an initial element.
pub const fn is_empty(&self) -> bool
[src]
Always returns false.
pub const fn first(&self) -> &T
[src]
Get the first element. Never fails.
pub fn push(&mut self, e: T)
[src]
Push an element to the end of the list.
pub fn pop(&mut self) -> Option<T>
[src]
Pop an element from the end of the list.
pub fn len(&self) -> usize
[src]
Get the length of the list.
pub fn last(&self) -> &T
[src]
Get the last element. Never fails.
pub fn last_mut(&mut self) -> &mut T
[src]
Get the last element mutably.
pub fn get(&self, index: usize) -> Option<&T>
[src]
Get an element by index.
pub fn get_mut(&mut self, index: usize) -> Option<&mut T>
[src]
Get an element by index, mutably.
pub fn truncate(&mut self, len: usize)
[src]
Truncate the list to a certain size. Must be greater than 0
.
pub fn iter<'a>(&'a self) -> impl Iterator<Item = &T> + 'a
[src]
use nonempty::NonEmpty; let mut l = NonEmpty::new(42); l.push(36); l.push(58); let mut l_iter = l.iter(); assert_eq!(l_iter.next(), Some(&42)); assert_eq!(l_iter.next(), Some(&36)); assert_eq!(l_iter.next(), Some(&58)); assert_eq!(l_iter.next(), None);
Trait Implementations
impl<T> Into<Vec<T>> for NonEmpty<T>
[src]
impl<T: Clone> Clone for NonEmpty<T>
[src]
impl<T: Debug> Debug for NonEmpty<T>
[src]
Auto Trait Implementations
impl<T> Send for NonEmpty<T> where
T: Send,
T: Send,
impl<T> Sync for NonEmpty<T> where
T: Sync,
T: Sync,
impl<T> Unpin for NonEmpty<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for NonEmpty<T> where
T: UnwindSafe,
T: UnwindSafe,
impl<T> RefUnwindSafe for NonEmpty<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,