I can allocate a slice with rust's typed_arena like this:
use typed_arena::Arena;
let arena = Arena::new();
let abc = arena.alloc_extend("abcdefg".chars().take(3));
However, I want to create a simple array with T::zero()
or T::default()
values. In theory I could create a slice with all those values, but it would be on the stack, which is bad, and I'd have to copy them to the allocated space.
Is there a way to allocate an array and get the mutable slice directly, using some default value?
The only way I see is to create an iterator that always returns the default value for size
times, but this does not seem like the best solution