move_into: Split into methods .move_into()
and .move_into_uninit()
.
#997
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Two methods for
Array
:.move_into(impl Into<ArrayViewMut<A, ..>>)
.move_into_uninit(impl Into<ArrayViewMut<MaybeUninit<A>, ..>>)
The
uninit
version is an optimization - it is more efficient since we don't need to keep track of the overwriting of existing values in the array. However, we optimize so that ifA
has no drop, they should be equivalent. So the user can use whichever fits best without worrying so much.The new
move_into
turned out to be very simple: just swap the elements in the old and new array. This means we never have a partially moved-from array to keep track of and no headaches. We simply delegate over to the non-drop method if we can. We also use aneeds_drop
check inmove_into_uninit
to skip all the complicated dropping code if the element type doesn't have drop.