Hello.
What is the most efficient way to create a new TinyVec of size length, which is initialized zero (or some user-defined value)?
Is there a better way than this?
#[inline(always)]
pub fn calloc_tinyvec<const N: usize>(length: usize) -> TinyVec<[u8; N]> {
let mut vec = TinyVec::with_capacity(length);
vec.resize(length, 0u8);
vec
}
Is this version preferible?
#[inline(always)]
pub fn calloc_tinyvec<const N: usize>(length: usize) -> TinyVec<[u8; N]> {
if length > N {
let mut vec = TinyVec::with_capacity(length);
vec.resize(length, 0u8);
vec
} else {
TinyVec::from_array_len([0u8; N], length)
}
}
Maybe it could be useful to have a method like:
TinyVec::with_size<A: Array>(length: usize, inital_value: T) -> TinyVec<A>
🤔
Best regards!