fizyk20 / generic-array

Generic array types in Rust
MIT License
404 stars 77 forks source link

Placement new #88

Open nickray opened 4 years ago

nickray commented 4 years ago

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.

novacrazy commented 4 years ago

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.

novacrazy commented 1 year ago

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