-
Notifications
You must be signed in to change notification settings - Fork 307
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
Add methods to collect Zip into an array #797
Conversation
In the grand scheme of things, it would be more exciting if
but it's not certain that the required changes are worth it. Or if @jturner314 hasn't implemented something similar already :) |
Now using MaybeUninit, because |
0b78e28
to
52d5286
Compare
Use MaybeUninit to handle uninitialized data safely.
Use Array::maybe_uniit to not need to zero result elements; Restrict to Copy, because we don't implement correct drop on panic yet.
52d5286
to
313f9a3
Compare
313f9a3
to
3ed3525
Compare
For non-Copy elements (more specifically, elements with drop, but we don't have a trait bound for that); there are hints of solutions for collect - I have an unbeautiful prototype for counting elements and dropping the right number of them on panic; but this doesn't transfer at all to the parallel case (in the parallel case, we have multiple different "write heads" into the array, and they all need to "roll back" if any thread panics), and that's a sign a better solution is needed of that problem. So it's not coming here. I'm also saying that I think it's important to handle drop correctly - on panic, the elements that were created should drop. It would be easy to ignore the problem by just saying that there is no drop handling, but I would judge that's not robust. That said, if |
(This is just a remainder from before pub(crate) was a feature we could use)
3ed3525
to
f7319b3
Compare
Add
Add internal (for now) constructors for
MaybeUninit<T>
-filled arrays.Restrict to Copy elements to use collect (because we don't implement dropping a
halfway filled array yet).
This is added to all but the last arity of Zip (because the last item is needed for the result that we collect into.
The assignment functions are generalized so that we can assign to
&mut T
,&mut MaybeUninit<T>
and&Cell<T>
when we have elements ofT
. This seems powerful, and could be a concept that's explored further (methods .assign() and .fill() come to mind).A very minor question is what to name and in which module to put the new trait for this -
AssignElem<T>
.Fixes #755