pub struct VecArray<T, const CAP: usize> { /* private fields */ }
Expand description
A Vec but entirely on the stack.
§Example
use vector_array::vec::VecArray;
let mut vec: VecArray<_, 10> = VecArray::new();
vec.push(9).unwrap();
assert_eq!(vec[0], 9);
Implementations§
Source§impl<T, const CAP: usize> VecArray<T, CAP>
impl<T, const CAP: usize> VecArray<T, CAP>
Sourcepub fn new_no_default() -> Self
pub fn new_no_default() -> Self
Creates a new VecArray. Use ::new if type has default especially if type contains pointers/references (think String, Box, etc)
§Example
use vector_array::vec::VecArray;
let mut vec: VecArray<_, 10> = VecArray::new_no_default();
vec.push(9).unwrap();
assert_eq!(vec[0], 9);
§Safety
There may be problems with drops if your type contains references for example. There also may be problems if you try to index in to parts of the array which are no yet initialized but this is nearly impossible.
Sourcepub fn new_arr(arr: [T; CAP], len: usize) -> Self
pub fn new_arr(arr: [T; CAP], len: usize) -> Self
Creates a new VecArray. Use when type doesnt implement default and (drop) safety is a problem.
Sourcepub fn push(&mut self, value: T) -> Result<(), ArrTooSmall>
pub fn push(&mut self, value: T) -> Result<(), ArrTooSmall>
Pushes an element.
§Example
use vector_array::vec::VecArray;
let mut vec: VecArray<_, 10> = VecArray::new();
vec.push(9).unwrap();
assert_eq!(vec[0], 9);
Sourcepub fn insert(&mut self, index: usize, element: T)
pub fn insert(&mut self, index: usize, element: T)
§Panics
If index is greater than or equal to length or new length is greater than CAP
§Example
use vector_array::{vec_arr, VecArray};
let mut vec: VecArray<_, 10> = vec_arr![1, 2, 3];
vec.insert(1, 4);
assert_eq!(vec, vec_arr![1, 4, 2, 3]);
vec.insert(2, 5);
assert_eq!(vec, vec_arr![1, 4, 5, 2, 3]);
§Safety
Copied from Vec source code
pub fn get(&self, index: usize) -> Option<&T>
pub fn set(&mut self, index: usize, value: T) -> Result<(), ArrTooSmall>
pub fn truncate(&mut self, len: usize)
pub fn last(&self) -> Option<&T>
pub fn first(&self) -> Option<&T>
pub fn iter(&self) -> Iter<'_, T> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, T>
pub fn as_mut_ptr(&mut self) -> *mut T
pub fn as_ptr(&self) -> *const T
Sourcepub unsafe fn get_arr(self) -> [T; CAP]
pub unsafe fn get_arr(self) -> [T; CAP]
Returns the entire array
§Safety
Can point to uninitialized memory, causes a segfault if memory is not properly initialized
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn as_slice(&self) -> &[T]
pub fn as_mut_slice(&mut self) -> &mut [T]
pub fn clear(&mut self)
pub fn capacity(&self) -> usize
Trait Implementations§
Source§impl<T, const CAP: usize> Default for VecArray<T, CAP>where
T: Default,
Does the same as ::new
impl<T, const CAP: usize> Default for VecArray<T, CAP>where
T: Default,
Does the same as ::new
Source§impl<T, const CAP: usize> IntoIterator for VecArray<T, CAP>
impl<T, const CAP: usize> IntoIterator for VecArray<T, CAP>
Auto Trait Implementations§
impl<T, const CAP: usize> Freeze for VecArray<T, CAP>where
T: Freeze,
impl<T, const CAP: usize> RefUnwindSafe for VecArray<T, CAP>where
T: RefUnwindSafe,
impl<T, const CAP: usize> Send for VecArray<T, CAP>where
T: Send,
impl<T, const CAP: usize> Sync for VecArray<T, CAP>where
T: Sync,
impl<T, const CAP: usize> Unpin for VecArray<T, CAP>where
T: Unpin,
impl<T, const CAP: usize> UnwindSafe for VecArray<T, CAP>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