pub struct DynamicVec<T, const STACK_SIZE: usize> { /* private fields */ }Expand description
A dynamic vector that can store elements on both the stack and the heap.
The DynamicVec struct provides a flexible vector implementation that can store elements
on the stack using the heapless::Vec type and on the heap using the Vec type.
It allows for efficient storage of small vectors on the stack while automatically
falling back to the heap for larger vectors.
§Examples
Creating a new DynamicVec:
use sans_io_runtime::collections::DynamicVec;
let mut vec: DynamicVec<u32, 10> = DynamicVec::default();Pushing elements into the DynamicVec:
use sans_io_runtime::collections::DynamicVec;
let mut vec: DynamicVec<u32, 10> = DynamicVec::default();
vec.push(1);
vec.push(2);
vec.push_stack(3).unwrap();Accessing elements in the DynamicVec:
use sans_io_runtime::collections::DynamicVec;
let mut vec: DynamicVec<u32, 10> = DynamicVec::default();
vec.push(1);
vec.push(2);
vec.push_stack(3).unwrap();
assert_eq!(vec.get(0), Some(&1));
assert_eq!(vec.get(1), Some(&2));
assert_eq!(vec.get(2), Some(&3));Implementations§
Source§impl<T, const STACK_SIZE: usize> DynamicVec<T, STACK_SIZE>
impl<T, const STACK_SIZE: usize> DynamicVec<T, STACK_SIZE>
Sourcepub fn from<const SIZE: usize>(prepare: [T; SIZE]) -> Self
pub fn from<const SIZE: usize>(prepare: [T; SIZE]) -> Self
Creates a new instance of DynamicVec from an array of elements.
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>
pub fn iter(&self) -> impl Iterator<Item = &T>
Sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut T>
pub fn get_mut(&mut self, index: usize) -> Option<&mut T>
Get the mutable element at the given index.
Sourcepub fn get_mut_or_panic(&mut self, index: usize) -> &mut T
pub fn get_mut_or_panic(&mut self, index: usize) -> &mut T
Get the mutable element at the given index or panic if not exists.
Sourcepub fn push_stack(&mut self, value: T) -> Result<(), T>
pub fn push_stack(&mut self, value: T) -> Result<(), T>
Push an element to the stack of the vector.
pub fn last(&self) -> Option<&T>
Trait Implementations§
Auto Trait Implementations§
impl<T, const STACK_SIZE: usize> Freeze for DynamicVec<T, STACK_SIZE>where
T: Freeze,
impl<T, const STACK_SIZE: usize> RefUnwindSafe for DynamicVec<T, STACK_SIZE>where
T: RefUnwindSafe,
impl<T, const STACK_SIZE: usize> Send for DynamicVec<T, STACK_SIZE>where
T: Send,
impl<T, const STACK_SIZE: usize> Sync for DynamicVec<T, STACK_SIZE>where
T: Sync,
impl<T, const STACK_SIZE: usize> Unpin for DynamicVec<T, STACK_SIZE>where
T: Unpin,
impl<T, const STACK_SIZE: usize> UnwindSafe for DynamicVec<T, STACK_SIZE>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