fizyk20/generic-array

Placement new

nickray opened this issue · 2 comments

Not sure how messy this would turn out, but has anybody experimented with a "GenericArray with borrowed data", where the constructor would inject a pre-allocated &mut [T; N::to_usize()]? Or in other words, exposing the applicable GenericArray methods to "views" of array slices.

Check out the from_slice methods or From<&[T]> implementations. They are checked for length, but with both parts having const lengths it should be optimized away.

I may have misinterpreted this originally. If you were looking for a way to allocate a raw buffer on the heap and then initialize it to some generic array with valid elements, that's a whole other can of worms. The Rust standard library is still trying to decide on the best way to handle MaybeUninit with heap memory.

It could be done, but at that point you may as well use a Vec