pub struct Nevec<T> { /* private fields */ }
Expand description

Non-empty vector type.

Implementations§

source§

impl<T> Nevec<T>

source

pub fn new(first: T) -> Nevec<T>

Creates a new Nevec with the provided first element.

source

pub fn with_capacity(first: T, capacity: usize) -> Nevec<T>

Creates a new Nevec with the provided first element and initial capacity.

source

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”).

source

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.

source

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.

source

pub fn push(&mut self, t: T)

Pushes an element onto the end of the vector.

source

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.

source

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.

source

pub fn len(&self) -> usize

Returns the length of the vector, which is guaranteed to be at least 1.

source

pub fn is_empty(&self) -> bool

Returns whether the vector is non-empty, which it always is.

source

pub fn get(&self, i: usize) -> Option<&T>

Get a reference to the element at the provided index.

source

pub fn get_mut(&mut self, i: usize) -> Option<&mut T>

Get a mutable reference to the element at the provided index.

Trait Implementations§

source§

impl<T: Clone> Clone for Nevec<T>

source§

fn clone(&self) -> Nevec<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Nevec<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Default> Default for Nevec<T>

source§

fn default() -> Nevec<T>

Returns the “default value” for a type. Read more
source§

impl<'de, T> Deserialize<'de> for Nevec<T>where T: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T: Display> Display for Nevec<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Index<usize> for Nevec<T>

§

type Output = T

The returned type after indexing.
source§

fn index(&self, i: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<'a, T> IntoIterator for &'a Nevec<T>

§

type Item = &'a T

The type of the elements being iterated over.
§

type IntoIter = NevecIter<'a, T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> NevecIter<'a, T>

Creates an iterator from a value. Read more
source§

impl<T> Serialize for Nevec<T>where T: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Nevec<T>where T: RefUnwindSafe,

§

impl<T> Send for Nevec<T>where T: Send,

§

impl<T> Sync for Nevec<T>where T: Sync,

§

impl<T> Unpin for Nevec<T>where T: Unpin,

§

impl<T> UnwindSafe for Nevec<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,