Follow

docs.rs/arrayvec/0.6.0/arrayve

Nice! ArrayVec's API now integrates perfectly with Rust const generics.

This is surprisingly useful for initializing arrays generically. Eg:

fn foo<T, U, const N: usize>(src: [T; N]) -> [U; N])
where T: Foo<U>
{
let mut r: ArrayVec<N> = ArrayVec::new();

for item in src {
r.push(item.foo());
}

r.into_inner().ok().unwrap()
}

On that basis alone I think ArrayVec should be added to the standard library. The alternative is MaybeUninit yuck.

· · Web · 0 · 0 · 0
Sign in to participate in the conversation
Mastodon

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!