Type Alias nunny::Vec

source ·
pub type Vec<T> = NonEmpty<Vec<T>>;
Expand description

A non-empty, heap allocated Vec.

Aliased Type§

struct Vec<T> { /* private fields */ }

Implementations§

source§

impl<T> Vec<T>

Vec methods

source

pub fn new_ref(src: &Vec<T>) -> Option<&Self>

Create a new NonEmpty heap-allocated vec

Returns None if src is empty.

source

pub fn new_mut(src: &mut Vec<T>) -> Option<&mut Self>

Create a new NonEmpty heap-allocated vec

Returns None if src is empty.

source

pub unsafe fn new_unchecked(src: Vec<T>) -> Self

Create a new NonEmpty heap-allocated vec

§Safety
  • src must not be empty
source

pub unsafe fn new_ref_unchecked(src: &Vec<T>) -> &Self

Create a new NonEmpty heap-allocated vec

§Safety
  • src must not be empty
source

pub unsafe fn new_mut_unchecked(src: &mut Vec<T>) -> &mut Self

Create a new NonEmpty heap-allocated vec

§Safety
  • src must not be empty
source

pub fn new(src: Vec<T>) -> Result<Self, Vec<T>>

Create a new NonEmpty heap-allocated vec, returning the original allocation if it was empty.

source

pub fn of(item: T) -> Self

Create a NonEmpty heap-allocated vec, of a single element.

source

pub fn of_with_capacity(item: T, capacity: usize) -> Self

Create a NonEmpty heap-allocated vec, of a single element, with capacity for capacity elements without (re)-allocating.

source

pub fn of_extending<A>(first: T, rest: impl IntoIterator<Item = A>) -> Self
where Self: Extend<A>,

Creating a NonEmpty heap-allocated vec where the first element is known.

This is an convenience method, equivalent to

let mut it = nunny::vec!["first"];
it.extend(["this", "is", "the", "rest"]);
source

pub fn filled(value: T, len: NonZeroUsize) -> Self
where T: Clone,

Create a NonEmpty heap-allocated vec with len items, filled with Clones of the given value.

See also Self::filled_with.

source

pub fn filled_with<F>(f: F, len: NonZeroUsize) -> Self
where F: FnMut() -> T,

Create a NonEmpty heap-allocated vec with len items, filled with values returned from repeating the closure f.

See also Self::filled.

source

pub fn as_vec(&self) -> &Vec<T>

Returns a std::vec::Vec.

source

pub unsafe fn as_mut_vec(&mut self) -> &mut Vec<T>

Returns a std::vec::Vec.

§Safety
  • returned vec must not be emptied through this reference
source

pub fn into_vec(self) -> Vec<T>

Returns a std::vec::Vec.

source

pub fn as_slice_ne(&self) -> &Slice<T>

Returns a NonEmpty slice.

source

pub fn as_mut_slice_ne(&mut self) -> &mut Slice<T>

Returns a NonEmpty slice.

source

pub fn capacity(&self) -> NonZeroUsize

Returns the known non-zero length.

source

pub fn reserve(&mut self, additional: usize)

See reserve.

source

pub fn reserve_exact(&mut self, additional: usize)

source

pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>

source

pub fn try_reserve_exact( &mut self, additional: usize, ) -> Result<(), TryReserveError>

source

pub fn shrink_to_fit(&mut self)

source

pub fn shrink_to(&mut self, min_capacity: usize)

See shrink_to.

source

pub fn into_boxed_slice(self) -> Box<Slice<T>>

Return a NonEmpty boxed slice.

source

pub fn truncate(&mut self, len: NonZeroUsize)

Shortens the vector to a guaranteed-nonzero length

See truncate.

source

pub unsafe fn set_len(&mut self, new_len: NonZeroUsize)

§Safety
source

pub fn insert(&mut self, index: usize, element: T)

See insert.

source

pub fn dedup_by_key<F, K>(&mut self, key: F)
where F: FnMut(&mut T) -> K, K: PartialEq,

source

pub fn dedup_by<F>(&mut self, same_bucket: F)
where F: FnMut(&mut T, &mut T) -> bool,

See dedup_by.

source

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

See push.

source

pub fn append(&mut self, other: &mut Vec<T>)

See append.

source

pub fn resize_with<F>(&mut self, new_len: NonZeroUsize, f: F)
where F: FnMut() -> T,

source

pub fn leak<'a>(self) -> &'a mut Slice<T>

Returns a NonEmpty slice.

See leak.

source

pub fn spare_capacity_mut(&mut self) -> &mut [MaybeUninit<T>]

source§

impl<T> Vec<T>

Known non-empty iterator for Vec.

Methods from Deref<Target = Slice<T>>§

source

pub fn each_ref(&self) -> Array<&T, N>

Borrows each element and returns a NonEmpty array of references with the same size as self.

source

pub fn each_mut(&mut self) -> Array<&mut T, N>

Borrows each element mutably and returns a NonEmpty array of mutable references with the same size as self.

source

pub fn as_slice_ne(&self) -> &Slice<T>

Returns a NonEmpty slice.

source

pub fn as_mut_slice_ne(&mut self) -> &mut Slice<T>

Returns a NonEmpty slice.

source

pub fn as_array(&self) -> &[T; N]

Returns a primitive array.

source

pub fn as_mut_array(&mut self) -> &mut [T; N]

Returns a primitive array.

source

pub fn peek(&mut self) -> &I::Item

Peek this NonEmpty iterator, without advancing it.

See Self::peekable.

source

pub fn peek_mut(&mut self) -> &mut I::Item

Peek and modify this NonEmpty iterator, without advancing it.

See Self::peekable.

source

pub fn as_slice(&self) -> &[T]

Returns a primitive slice.

source

pub fn as_mut_slice(&mut self) -> &mut [T]

Returns a primitive slice.

source

pub fn len_ne(&self) -> NonZeroUsize

Returns the known non-zero length.

source

pub fn first(&self) -> &T

Returns the first element, guaranteed.

source

pub fn split_first(&self) -> (&T, &[T])

Returns the first element, guaranteed, and the rest of the elements.

source

pub fn split_last(&self) -> (&T, &[T])

Returns the last element, guaranteed, and the rest of the elements.

source

pub fn last(&self) -> &T

Returns the last element, guaranteed.

source

pub fn first_mut(&mut self) -> &mut T

Returns the first element, guaranteed.

source

pub fn split_first_mut(&mut self) -> (&mut T, &mut [T])

Returns the first element, guaranteed, and the rest of the elements.

source

pub fn split_last_mut(&mut self) -> (&mut T, &mut [T])

Returns the last element, guaranteed, and the rest of the elements.

source

pub fn last_mut(&mut self) -> &mut T

Returns the last element, guaranteed.

source

pub fn iter_ne(&self) -> NonEmpty<Iter<'_, T>>

source

pub fn iter_mut_ne(&mut self) -> NonEmpty<IterMut<'_, T>>

source

pub fn as_vec(&self) -> &Vec<T>

Returns a std::vec::Vec.

source

pub unsafe fn as_mut_vec(&mut self) -> &mut Vec<T>

Returns a std::vec::Vec.

§Safety
  • returned vec must not be emptied through this reference
source

pub fn as_slice_ne(&self) -> &Slice<T>

Returns a NonEmpty slice.

source

pub fn as_mut_slice_ne(&mut self) -> &mut Slice<T>

Returns a NonEmpty slice.

source

pub fn capacity(&self) -> NonZeroUsize

Returns the known non-zero length.

source

pub fn reserve(&mut self, additional: usize)

See reserve.

source

pub fn reserve_exact(&mut self, additional: usize)

source

pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>

source

pub fn try_reserve_exact( &mut self, additional: usize, ) -> Result<(), TryReserveError>

source

pub fn shrink_to_fit(&mut self)

source

pub fn shrink_to(&mut self, min_capacity: usize)

See shrink_to.

source

pub fn truncate(&mut self, len: NonZeroUsize)

Shortens the vector to a guaranteed-nonzero length

See truncate.

source

pub unsafe fn set_len(&mut self, new_len: NonZeroUsize)

§Safety
source

pub fn insert(&mut self, index: usize, element: T)

See insert.

source

pub fn dedup_by_key<F, K>(&mut self, key: F)
where F: FnMut(&mut T) -> K, K: PartialEq,

source

pub fn dedup_by<F>(&mut self, same_bucket: F)
where F: FnMut(&mut T, &mut T) -> bool,

See dedup_by.

source

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

See push.

source

pub fn append(&mut self, other: &mut Vec<T>)

See append.

source

pub fn resize_with<F>(&mut self, new_len: NonZeroUsize, f: F)
where F: FnMut() -> T,

source

pub fn spare_capacity_mut(&mut self) -> &mut [MaybeUninit<T>]

Trait Implementations§

source§

impl<T> Arbitrary for Vec<T>
where T: Arbitrary,

source§

fn arbitrary(g: &mut Gen) -> Self

Return an arbitrary value. Read more
source§

fn shrink(&self) -> Box<dyn Iterator<Item = Self>>

Return an iterator of values that are smaller than itself. Read more
source§

impl<T> AsMut<[T]> for Vec<T>

source§

fn as_mut(&mut self) -> &mut [T]

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<T> AsMut<NonEmpty<[T]>> for Vec<T>

source§

fn as_mut(&mut self) -> &mut Slice<T>

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<T> AsMut<NonEmpty<Vec<T>>> for Vec<T>

source§

fn as_mut(&mut self) -> &mut Self

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<T> AsRef<[T]> for Vec<T>

source§

fn as_ref(&self) -> &[T]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T> AsRef<NonEmpty<[T]>> for Vec<T>

source§

fn as_ref(&self) -> &Slice<T>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T> AsRef<NonEmpty<Vec<T>>> for Vec<T>

source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T> Borrow<[T]> for Vec<T>

source§

fn borrow(&self) -> &[T]

Immutably borrows from an owned value. Read more
source§

impl<T> Borrow<NonEmpty<[T]>> for Vec<T>

source§

fn borrow(&self) -> &Slice<T>

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<[T]> for Vec<T>

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<NonEmpty<[T]>> for Vec<T>

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> Deref for Vec<T>

§

type Target = NonEmpty<[T]>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T> DerefMut for Vec<T>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<'de, T> Deserialize<'de> for Vec<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<'a, T> Extend<&'a T> for Vec<T>
where T: Copy + 'a,

source§

fn extend<II: IntoIterator<Item = &'a T>>(&mut self, iter: II)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<T> Extend<T> for Vec<T>

source§

fn extend<II: IntoIterator<Item = T>>(&mut self, iter: II)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<T> From<&NonEmpty<[T]>> for Vec<T>
where T: Clone,

source§

fn from(value: &Slice<T>) -> Self

Converts to this type from the input type.
source§

impl<const N: usize, T> From<&NonEmpty<[T; N]>> for Vec<T>
where T: Clone,

source§

fn from(value: &Array<T, N>) -> Self

Converts to this type from the input type.
source§

impl<T> From<&mut NonEmpty<[T]>> for Vec<T>
where T: Clone,

source§

fn from(value: &mut Slice<T>) -> Self

Converts to this type from the input type.
source§

impl<const N: usize, T> From<&mut NonEmpty<[T; N]>> for Vec<T>
where T: Clone,

source§

fn from(value: &mut Array<T, N>) -> Self

Converts to this type from the input type.
source§

impl<T> From<Box<NonEmpty<[T]>>> for Vec<T>

source§

fn from(value: Box<Slice<T>>) -> Self

Converts to this type from the input type.
source§

impl<'a, T> From<Cow<'a, NonEmpty<[T]>>> for Vec<T>
where Slice<T>: ToOwned<Owned = Vec<T>>,

source§

fn from(value: Cow<'a, Slice<T>>) -> Self

Converts to this type from the input type.
source§

impl<const N: usize, T> From<NonEmpty<[T; N]>> for Vec<T>

source§

fn from(value: Array<T, N>) -> Self

Converts to this type from the input type.
source§

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

§

type Item = &'a T

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, T>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, T> IntoIterator for &'a mut Vec<T>

§

type Item = &'a mut T

The type of the elements being iterated over.
§

type IntoIter = IterMut<'a, T>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T> IntoIterator for Vec<T>

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<T>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T> JsonSchema for Vec<T>
where T: JsonSchema,

source§

fn schema_name() -> String

The name of the generated JSON Schema. Read more
source§

fn json_schema(gen: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
source§

fn is_referenceable() -> bool

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more
source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
source§

impl<T> Ord for Vec<T>
where T: Ord,

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<T, U> PartialEq<&NonEmpty<[U]>> for Vec<T>
where T: PartialEq<U>,

source§

fn eq(&self, other: &&Slice<U>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, U, const N: usize> PartialEq<&NonEmpty<[U; N]>> for Vec<T>
where T: PartialEq<U>,

source§

fn eq(&self, other: &&Array<U, N>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, U> PartialEq<&mut NonEmpty<[U]>> for Vec<T>
where T: PartialEq<U>,

source§

fn eq(&self, other: &&mut Slice<U>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, U> PartialEq<[U]> for Vec<T>
where T: PartialEq<U>,

source§

fn eq(&self, other: &[U]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, U, const N: usize> PartialEq<[U; N]> for Vec<T>
where T: PartialEq<U>,

source§

fn eq(&self, other: &[U; N]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, U> PartialEq<NonEmpty<[U]>> for Vec<T>
where T: PartialEq<U>,

source§

fn eq(&self, other: &Slice<U>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, U, const N: usize> PartialEq<NonEmpty<[U; N]>> for Vec<T>
where T: PartialEq<U>,

source§

fn eq(&self, other: &Array<U, N>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, U> PartialEq<NonEmpty<Vec<U>>> for Vec<T>
where T: PartialEq<U>,

source§

fn eq(&self, other: &Vec<U>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, U> PartialEq<Vec<U>> for Vec<T>
where T: PartialEq<U>,

source§

fn eq(&self, other: &Vec<U>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> PartialOrd<[T]> for Vec<T>
where T: PartialOrd,

source§

fn partial_cmp(&self, other: &[T]) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T, const N: usize> PartialOrd<[T; N]> for Vec<T>
where T: PartialOrd,

source§

fn partial_cmp(&self, other: &[T; N]) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T> PartialOrd<Vec<T>> for Vec<T>
where T: PartialOrd,

source§

fn partial_cmp(&self, other: &Vec<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T> PartialOrd for Vec<T>
where T: PartialOrd,

source§

fn partial_cmp(&self, other: &Vec<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T> Serialize for Vec<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
source§

impl<'a, T> TryFrom<&'a Vec<T>> for &'a Vec<T>

§

type Error = Error

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

fn try_from(value: &'a Vec<T>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a, T> TryFrom<&'a mut Vec<T>> for &'a mut Vec<T>

§

type Error = Error

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

fn try_from(value: &'a mut Vec<T>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<T> TryFrom<Vec<T>> for Vec<T>

§

type Error = Vec<T>

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

fn try_from(value: Vec<T>) -> Result<Self, Self::Error>

Performs the conversion.