VecView

Type Alias VecView 

Source
pub type VecView<T, LenT = usize> = VecInner<T, LenT, ViewVecStorage<T>>;
Expand description

A Vec with dynamic capacity

Vec coerces to VecView. VecView is !Sized, meaning it can only ever be used by reference.

Unlike Vec, VecView does not have an N const-generic parameter. This has the ergonomic advantage of making it possible to use functions without needing to know at compile-time the size of the buffers used, for example for use in dyn traits.

VecView<T> is to Vec<T, N> what [T] is to [T; N].

use heapless::{Vec, VecView};

let mut vec: Vec<u8, 10> = Vec::from_slice(&[1, 2, 3, 4]).unwrap();
let view: &VecView<_, _> = &vec;
assert_eq!(view, &[1, 2, 3, 4]);

let mut_view: &mut VecView<_, _> = &mut vec;
mut_view.push(5);
assert_eq!(vec, [1, 2, 3, 4, 5]);

Aliased Typeยง

pub struct VecView<T, LenT = usize> { /* private fields */ }