DynamicVec

Struct DynamicVec 

Source
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>

Source

pub fn from<const SIZE: usize>(prepare: [T; SIZE]) -> Self

Creates a new instance of DynamicVec from an array of elements.

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>

Source

pub fn iter(&self) -> impl Iterator<Item = &T>

Source

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

Get the element at the given index.

Source

pub fn set(&mut self, index: usize, value: T)

Set the element at the given index.

Source

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

Get the mutable element at the given index.

Source

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.

Source

pub fn push_stack(&mut self, value: T) -> Result<(), T>

Push an element to the stack of the vector.

Source

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

Push an element to the stack or the heap of the vector.

Source

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

Pops the element from the end of the vector.

Source

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

Source

pub fn is_empty(&self) -> bool

Check if the vector is empty.

Source

pub fn len(&self) -> usize

Returns the number of elements in the vector.

Trait Implementations§

Source§

impl<T: Debug, const STACK_SIZE: usize> Debug for DynamicVec<T, STACK_SIZE>

Source§

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

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

impl<T, const STACK_SIZE: usize> Default for DynamicVec<T, STACK_SIZE>

Source§

fn default() -> Self

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

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.