[][src]Struct staticvec::StaticVec

pub struct StaticVec<T, const N: usize> { /* fields omitted */ }

A Vec-like struct (mostly directly API-compatible where it can be) implemented with const generics around an array of fixed N capacity.

Methods

impl<T, const N: usize> StaticVec<T, { N }>[src]

pub fn new() -> Self[src]

Returns a new StaticVec instance.

pub fn new_from_slice(values: &[T]) -> Self where
    T: Copy
[src]

Returns a new StaticVec instance filled with the contents, if any, of a slice reference, which can be either &mut or & as if it is &mut it will implicitly coerce to &. If the slice has a length greater than the StaticVec's declared capacity, any contents after that point are ignored. Locally requires that T implements Copy to avoid soundness issues.

pub fn new_from_array<const N2: usize>(values: [T; N2]) -> Self[src]

Returns a new StaticVec instance filled with the contents, if any, of an array. If the array has a length greater than the StaticVec's declared capacity, any contents after that point are ignored. The N2 parameter does not need to be provided explicitly, and can be inferred from the array itself. This function does not leak memory, as any ignored extra elements in the source array are explicitly dropped with drop_in_place before forget is called on it.

pub fn filled_with<F>(initializer: F) -> Self where
    F: FnMut() -> T, 
[src]

Returns a new StaticVec instance filled with the return value of an initializer function. The length field of the newly created StaticVec will be equal to its capacity.

Example usage:

let mut i = 0;
let v = StaticVec::<i32, 64>::filled_with(|| { i += 1; i });
assert_eq!(v.len(), 64);
assert_eq!(v[0], 1);
assert_eq!(v[1], 2);
assert_eq!(v[2], 3);
assert_eq!(v[3], 4);

pub fn filled_with_by_index<F>(initializer: F) -> Self where
    F: FnMut(usize) -> T, 
[src]

Returns a new StaticVec instance filled with the return value of an initializer function. Unlike for filled_with, the initializer function in this case must take a single usize variable as an input parameter, which will be called with the current index of the 0..N loop that filled_with_by_index is implemented with internally. The length field of the newly created StaticVec will be equal to its capacity.

Example usage:

let v = StaticVec::<usize, 64>::filled_with_by_index(|i| { i + 1 });
assert_eq!(v.len(), 64);
assert_eq!(v[0], 1);
assert_eq!(v[1], 2);
assert_eq!(v[2], 3);
assert_eq!(v[3], 4);

pub const fn len(&self) -> usize[src]

Returns the current length of the StaticVec. Just as for a normal Vec, this means the number of elements that have been added to it with push, insert, etc. except in the case that it has been set directly with the unsafe set_len function.

pub const fn capacity(&self) -> usize[src]

Returns the total capacity of the StaticVec. This is always equivalent to the generic N parameter it was declared with, which determines the fixed size of the backing array.

pub const fn cap() -> usize[src]

Does the same thing as capacity, but as an associated function rather than a method.

pub const CAPACITY: usize[src]

Serves the same purpose as capacity, but as an associated constant rather than a method.

pub const fn remaining_capacity(&self) -> usize[src]

Returns the remaining capacity of the StaticVec.

pub unsafe fn set_len(&mut self, new_len: usize)[src]

Directly sets the length field of the StaticVec to new_len. Useful if you intend to write to it solely element-wise, but marked unsafe due to how it creates the potential for reading from unitialized memory later on.

pub const fn is_empty(&self) -> bool[src]

Returns true if the current length of the StaticVec is 0.

pub const fn is_not_empty(&self) -> bool[src]

Returns true if the current length of the StaticVec is greater than 0.

pub const fn is_full(&self) -> bool[src]

Returns true if the current length of the StaticVec is equal to its capacity.

pub const fn is_not_full(&self) -> bool[src]

Returns true if the current length of the StaticVec is less than its capacity.

pub fn as_ptr(&self) -> *const T[src]

Returns a constant pointer to the first element of the StaticVec's internal array.

pub fn as_mut_ptr(&mut self) -> *mut T[src]

Returns a mutable pointer to the first element of the StaticVec's internal array.

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

Returns a constant reference to a slice of the StaticVec's inhabited area.

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

Returns a mutable reference to a slice of the StaticVec's inhabited area.

pub unsafe fn get_unchecked(&self, index: usize) -> &T[src]

Returns a constant reference to the element of the StaticVec at index, if index is within the range 0..length. No checks are performed to ensure that is the case, so this function is marked unsafe and should be used with caution only when performance is absolutely paramount.

Note that, unlike slice::get_unchecked, this method only supports accessing individual elements via usize; it cannot also produce subslices. To unsafely get a subslice without a bounds check, use vec.as_slice().get_unchecked(a..b).

Safety

It is up to the caller to ensure that index is within the appropriate bounds.

pub unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T[src]

Returns a mutable reference to the element of the StaticVec at index, if index is within the range 0..length. No checks are performed to ensure that is the case, so this function is marked unsafe and should be used with caution only when performance is absolutely paramount.

The same differences between this method and the slice method of the same name apply as do for get_unchecked.

Safety

It is up to the caller to ensure that index is within the appropriate bounds.

pub unsafe fn push_unchecked(&mut self, value: T)[src]

Appends a value to the end of the StaticVec without asserting that its current length is less than N.

pub unsafe fn pop_unchecked(&mut self) -> T[src]

Pops a value from the end of the StaticVec and returns it directly without asserting that the StaticVec's current length is greater than 0.

pub fn try_push(&mut self, value: T) -> Result<(), &'static str>[src]

Pushes value to the StaticVec if its current length is less than its capacity, or returns an error indicating there's no remaining capacity otherwise.

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

Push a value to the end of this StaticVec. Panics if the collection is full; that is, if self.len() == self.capacity().

pub fn pop(&mut self) -> Option<T>[src]

Removes the value at the last position of the StaticVec and returns it in Some if the StaticVec has a current length greater than 0, and returns None otherwise.

pub fn first(&self) -> Option<&T>[src]

Returns a constant reference to the first element of the StaticVec in Some if the StaticVec is not empty, or None otherwise.

pub fn first_mut(&mut self) -> Option<&mut T>[src]

Returns a mutable reference to the first element of the StaticVec in Some if the StaticVec is not empty, or None otherwise.

pub fn last(&self) -> Option<&T>[src]

Returns a constant reference to the last element of the StaticVec in Some if the StaticVec is not empty, or None otherwise.

pub fn last_mut(&mut self) -> Option<&mut T>[src]

Returns a mutable reference to the last element of the StaticVec in Some if the StaticVec is not empty, or None otherwise.

pub fn remove(&mut self, index: usize) -> T[src]

Asserts that index is less than the current length of the StaticVec, and if so removes the value at that position and returns it. Any values that exist in later positions are shifted to the left.

pub fn remove_item(&mut self, item: &T) -> Option<T> where
    T: PartialEq
[src]

Removes the first instance of item from the StaticVec if the item exists.

pub fn swap_pop(&mut self, index: usize) -> Option<T>[src]

Returns None if index is greater than or equal to the current length of the StaticVec. Otherwise, removes the value at that position and returns it in Some, and then moves the last value in the StaticVec into the empty slot.

pub fn swap_remove(&mut self, index: usize) -> T[src]

Asserts that index is less than the current length of the StaticVec, and if so removes the value at that position and returns it, and then moves the last value in the StaticVec into the empty slot.

pub fn insert(&mut self, index: usize, value: T)[src]

Asserts that the current length of the StaticVec is less than N and that index is less than the length, and if so inserts value at that position. Any values that exist in positions after index are shifted to the right.

pub fn try_insert(&mut self, index: usize, value: T) -> Result<(), &'static str>[src]

Inserts value at index if the current length of the StaticVec is less than N and index is less than the length, or returns a error stating one of the two is not the case otherwise. Any values that exist in positions after index are shifted to the right.

pub fn clear(&mut self)[src]

Removes all contents from the StaticVec and sets its length back to 0.

Important traits for StaticVecIterConst<'a, T>
pub fn iter<'a>(&'a self) -> StaticVecIterConst<'a, T>[src]

Returns a StaticVecIterConst over the StaticVec's inhabited area.

Important traits for StaticVecIterMut<'a, T>
pub fn iter_mut<'a>(&'a mut self) -> StaticVecIterMut<'a, T>[src]

Returns a StaticVecIterMut over the StaticVec's inhabited area.

pub fn sorted(&self) -> Self where
    T: Copy + Ord
[src]

This is supported on feature="std" only.

Returns a separate, stable-sorted StaticVec of the contents of the StaticVec's inhabited area without modifying the original data. Locally requires that T implements Copy to avoid soundness issues, and Ord to make the sorting possible.

pub fn sorted_unstable(&self) -> Self where
    T: Copy + Ord
[src]

Returns a separate, unstable-sorted StaticVec of the contents of the StaticVec's inhabited area without modifying the original data. Locally requires that T implements Copy to avoid soundness issues, and Ord to make the sorting possible.

pub fn reversed(&self) -> Self where
    T: Copy
[src]

Returns a separate, reversed StaticVec of the contents of the StaticVec's inhabited area without modifying the original data. Locally requires that T implements Copy to avoid soundness issues.

pub fn extend_from_slice(&mut self, other: &[T]) where
    T: Copy
[src]

Copies and appends all elements, if any, of a slice (which can also be &mut as it will coerce implicitly to &) to the StaticVec. If the slice has a length greater than the StaticVec's remaining capacity, any contents after that point are ignored. Locally requires that T implements Copy to avoid soundness issues.

pub fn try_extend_from_slice(&mut self, other: &[T]) -> Result<(), &'static str> where
    T: Copy
[src]

Copies and appends all elements, if any, of a slice to the StaticVec if the StaticVec's remaining capacity is greater than the length of the slice, or returns an error indicating that's not the case otherwise.

pub fn into_vec(&mut self) -> Vec<T>[src]

This is supported on feature="std" only.

Returns a Vec containing the contents of the StaticVec instance. The returned Vec will initially have the same value for len and capacity as the source StaticVec. Note that while using this function does not consume the source StaticVec in the sense of rendering it completely inaccessible / unusable, it does empty it (that is, it will have no contents and a length of 0 afterwards.)

pub fn drain<R>(&mut self, range: R) -> Self where
    R: RangeBounds<usize>, 
[src]

Removes the specified range of elements from the StaticVec and returns them in a new one.

pub fn drain_filter<F>(&mut self, filter: F) -> Self where
    F: FnMut(&mut T) -> bool
[src]

Removes all elements in the StaticVec for which filter returns true and returns them in a new one.

pub fn retain<F>(&mut self, filter: F) where
    F: FnMut(&T) -> bool
[src]

Removes all elements in the StaticVec for which filter returns false.

pub fn truncate(&mut self, length: usize)[src]

Shortens the StaticVec, keeping the first length elements and dropping the rest. Does nothing if length is greater than or equal to the current length of the StaticVec.

pub fn split_off(&mut self, at: usize) -> Self[src]

Splits the StaticVec into two at the given index. The original StaticVec will contain elements 0..at, and the new one will contain elements at..length.

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

Removes all but the first of consecutive elements in the StaticVec satisfying a given equality relation.

pub fn dedup(&mut self) where
    T: PartialEq
[src]

Removes consecutive repeated elements in the StaticVec according to the locally required PartialEq trait implementation for T.

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

Removes all but the first of consecutive elements in the StaticVec that resolve to the same key.

Trait Implementations

impl<T, const N: usize> Deref for StaticVec<T, { N }>[src]

type Target = [T]

The resulting type after dereferencing.

impl<T, const N: usize> DerefMut for StaticVec<T, { N }>[src]

impl<'_, T: Copy, const N: usize> From<&'_ [T]> for StaticVec<T, { N }>[src]

fn from(values: &[T]) -> Self[src]

Creates a new StaticVec instance from the contents of values, using new_from_slice internally.

impl<'_, T: Copy, const N: usize> From<&'_ mut [T]> for StaticVec<T, { N }>[src]

fn from(values: &mut [T]) -> Self[src]

Creates a new StaticVec instance from the contents of values, using new_from_slice internally.

impl<T, const N1: usize, const N2: usize> From<[T; N1]> for StaticVec<T, { N2 }>[src]

fn from(values: [T; N1]) -> Self[src]

Creates a new StaticVec instance from the contents of values, using new_from_array internally.

impl<'_, T: Copy, const N1: usize, const N2: usize> From<&'_ [T; N1]> for StaticVec<T, { N2 }>[src]

fn from(values: &[T; N1]) -> Self[src]

Creates a new StaticVec instance from the contents of values, using new_from_slice internally.

impl<'_, T: Copy, const N1: usize, const N2: usize> From<&'_ mut [T; N1]> for StaticVec<T, { N2 }>[src]

fn from(values: &mut [T; N1]) -> Self[src]

Creates a new StaticVec instance from the contents of values, using new_from_slice internally.

impl<T: Debug, const N: usize> Debug for StaticVec<T, { N }>[src]

impl<T1, T2: PartialEq<T1>, const N1: usize, const N2: usize> PartialEq<StaticVec<T1, N1>> for StaticVec<T2, { N2 }>[src]

impl<'_, T1, T2: PartialEq<T1>, const N1: usize, const N2: usize> PartialEq<StaticVec<T1, N1>> for &'_ StaticVec<T2, { N2 }>[src]

impl<'_, T1, T2: PartialEq<T1>, const N1: usize, const N2: usize> PartialEq<StaticVec<T1, N1>> for &'_ mut StaticVec<T2, { N2 }>[src]

impl<'_, T1, T2: PartialEq<T1>, const N1: usize, const N2: usize> PartialEq<&'_ StaticVec<T1, N1>> for StaticVec<T2, { N2 }>[src]

impl<'_, T1, T2: PartialEq<T1>, const N1: usize, const N2: usize> PartialEq<&'_ mut StaticVec<T1, N1>> for StaticVec<T2, { N2 }>[src]

impl<T1, T2: PartialEq<T1>, const N1: usize, const N2: usize> PartialEq<[T1; N1]> for StaticVec<T2, { N2 }>[src]

impl<'_, T1, T2: PartialEq<T1>, const N1: usize, const N2: usize> PartialEq<[T1; N1]> for &'_ StaticVec<T2, { N2 }>[src]

impl<'_, T1, T2: PartialEq<T1>, const N1: usize, const N2: usize> PartialEq<[T1; N1]> for &'_ mut StaticVec<T2, { N2 }>[src]

impl<'_, T1, T2: PartialEq<T1>, const N1: usize, const N2: usize> PartialEq<&'_ [T1; N1]> for StaticVec<T2, { N2 }>[src]

impl<'_, T1, T2: PartialEq<T1>, const N1: usize, const N2: usize> PartialEq<&'_ mut [T1; N1]> for StaticVec<T2, { N2 }>[src]

impl<T1, T2: PartialEq<T1>, const N: usize> PartialEq<[T1]> for StaticVec<T2, { N }>[src]

impl<'_, T1, T2: PartialEq<T1>, const N: usize> PartialEq<[T1]> for &'_ StaticVec<T2, { N }>[src]

impl<'_, T1, T2: PartialEq<T1>, const N: usize> PartialEq<[T1]> for &'_ mut StaticVec<T2, { N }>[src]

impl<'_, T1, T2: PartialEq<T1>, const N: usize> PartialEq<&'_ [T1]> for StaticVec<T2, { N }>[src]

impl<'_, T1, T2: PartialEq<T1>, const N: usize> PartialEq<&'_ mut [T1]> for StaticVec<T2, { N }>[src]

impl<T: Eq, const N: usize> Eq for StaticVec<T, { N }>[src]

impl<T: Ord, const N: usize> Ord for StaticVec<T, { N }>[src]

impl<T1, T2: PartialOrd<T1>, const N1: usize, const N2: usize> PartialOrd<StaticVec<T1, N1>> for StaticVec<T2, { N2 }>[src]

impl<'_, T1, T2: PartialOrd<T1>, const N1: usize, const N2: usize> PartialOrd<StaticVec<T1, N1>> for &'_ StaticVec<T2, { N2 }>[src]

impl<'_, T1, T2: PartialOrd<T1>, const N1: usize, const N2: usize> PartialOrd<StaticVec<T1, N1>> for &'_ mut StaticVec<T2, { N2 }>[src]

impl<'_, T1, T2: PartialOrd<T1>, const N1: usize, const N2: usize> PartialOrd<&'_ StaticVec<T1, N1>> for StaticVec<T2, { N2 }>[src]

impl<'_, T1, T2: PartialOrd<T1>, const N1: usize, const N2: usize> PartialOrd<&'_ mut StaticVec<T1, N1>> for StaticVec<T2, { N2 }>[src]

impl<T1, T2: PartialOrd<T1>, const N1: usize, const N2: usize> PartialOrd<[T1; N1]> for StaticVec<T2, { N2 }>[src]

impl<'_, T1, T2: PartialOrd<T1>, const N1: usize, const N2: usize> PartialOrd<[T1; N1]> for &'_ StaticVec<T2, { N2 }>[src]

impl<'_, T1, T2: PartialOrd<T1>, const N1: usize, const N2: usize> PartialOrd<[T1; N1]> for &'_ mut StaticVec<T2, { N2 }>[src]

impl<'_, T1, T2: PartialOrd<T1>, const N1: usize, const N2: usize> PartialOrd<&'_ [T1; N1]> for StaticVec<T2, { N2 }>[src]

impl<'_, T1, T2: PartialOrd<T1>, const N1: usize, const N2: usize> PartialOrd<&'_ mut [T1; N1]> for StaticVec<T2, { N2 }>[src]

impl<T1, T2: PartialOrd<T1>, const N: usize> PartialOrd<[T1]> for StaticVec<T2, { N }>[src]

impl<'_, T1, T2: PartialOrd<T1>, const N: usize> PartialOrd<[T1]> for &'_ StaticVec<T2, { N }>[src]

impl<'_, T1, T2: PartialOrd<T1>, const N: usize> PartialOrd<[T1]> for &'_ mut StaticVec<T2, { N }>[src]

impl<'_, T1, T2: PartialOrd<T1>, const N: usize> PartialOrd<&'_ [T1]> for StaticVec<T2, { N }>[src]

impl<'_, T1, T2: PartialOrd<T1>, const N: usize> PartialOrd<&'_ mut [T1]> for StaticVec<T2, { N }>[src]

impl<T, const N: usize> Drop for StaticVec<T, { N }>[src]

impl<T, I: SliceIndex<[T]>, const N: usize> Index<I> for StaticVec<T, { N }>[src]

type Output = I::Output

The returned type after indexing.

impl<T, I: SliceIndex<[T]>, const N: usize> IndexMut<I> for StaticVec<T, { N }>[src]

impl<T: Hash, const N: usize> Hash for StaticVec<T, { N }>[src]

impl<T, const N: usize> FromIterator<T> for StaticVec<T, { N }>[src]

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self[src]

Creates a new StaticVec instance from the elements, if any, of iter. If iter has a size greater than the StaticVec's capacity, any items after that point are ignored.

impl<'a, T: 'a + Copy, const N: usize> FromIterator<&'a T> for StaticVec<T, { N }>[src]

fn from_iter<I: IntoIterator<Item = &'a T>>(iter: I) -> Self[src]

Creates a new StaticVec instance from the elements, if any, of iter. If iter has a size greater than the StaticVec's capacity, any items after that point are ignored.

impl<'a, T: 'a, const N: usize> IntoIterator for &'a StaticVec<T, { N }>[src]

type IntoIter = StaticVecIterConst<'a, T>

Which kind of iterator are we turning this into?

type Item = &'a T

The type of the elements being iterated over.

fn into_iter(self) -> Self::IntoIter[src]

Returns a StaticVecIterConst over the StaticVec's inhabited area.

impl<'a, T: 'a, const N: usize> IntoIterator for &'a mut StaticVec<T, { N }>[src]

type IntoIter = StaticVecIterMut<'a, T>

Which kind of iterator are we turning this into?

type Item = &'a mut T

The type of the elements being iterated over.

fn into_iter(self) -> Self::IntoIter[src]

Returns a StaticVecIterMut over the StaticVec's inhabited area.

impl<T, const N: usize> Extend<T> for StaticVec<T, { N }>[src]

fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)[src]

Appends all elements, if any, from iter to the StaticVec. If iter has a size greater than the StaticVec's capacity, any items after that point are ignored.

impl<'a, T: 'a + Copy, const N: usize> Extend<&'a T> for StaticVec<T, { N }>[src]

fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I)[src]

Appends all elements, if any, from iter to the StaticVec. If iter has a size greater than the StaticVec's capacity, any items after that point are ignored.

impl<T, const N: usize> AsRef<[T]> for StaticVec<T, { N }>[src]

impl<T, const N: usize> AsMut<[T]> for StaticVec<T, { N }>[src]

impl<'_, T, const N: usize> Into<Vec<T>> for &'_ mut StaticVec<T, { N }>[src]

fn into(self) -> Vec<T>[src]

Functionally equivalent to into_vec.

impl<T: Clone, const N: usize> Clone for StaticVec<T, { N }>[src]

impl<T: Copy, const N: usize> Clone for StaticVec<T, { N }>[src]

impl<T, const N: usize> Default for StaticVec<T, { N }>[src]

fn default() -> Self[src]

Calls new.

impl<const N: usize> Read for StaticVec<u8, { N }>[src]

Read from a StaticVec. This implementation reads from the StaticVec by copying bytes into the destination buffers, then shifting the remaining bytes over. This might be inefficient for your needs; consider using Cursor or [T] as Read for more efficient ways to read out of a StaticVec without mutating it.

impl<const N: usize> Write for StaticVec<u8, { N }>[src]

Auto Trait Implementations

impl<const N: usize, T> Unpin for StaticVec<T, N> where
    T: Unpin

impl<const N: usize, T> Send for StaticVec<T, N> where
    T: Send

impl<const N: usize, T> Sync for StaticVec<T, N> where
    T: Sync

impl<const N: usize, T> UnwindSafe for StaticVec<T, N> where
    T: UnwindSafe

impl<const N: usize, T> RefUnwindSafe for StaticVec<T, N> where
    T: RefUnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.