Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Placement new #88

Open
nickray opened this issue Jan 5, 2020 · 2 comments
Open

Placement new #88

nickray opened this issue Jan 5, 2020 · 2 comments

Comments

@nickray
Copy link

nickray commented Jan 5, 2020

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
Copy link
Collaborator

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants