nonempty
nonempty copied to clipboard
remove methods
Adds the following methods
-
checked_remove: checks if the element at a certain index can be removed from the vector, then removes it, shifting all elements after it to the left. If it is not possible to remove, returns aRemoveError -
remove: calls checked_remove, then unwraps -
checked_swap_remove: checks if the element at a certain index can be removed from the vector, then removes it, replacing it with the last element. If it is not possible to remove, returns aRemoveError -
swap_remove: calls checked_swap_remove, then unwraps
All of the above methods return the removed element (if any).
Also add a RemoveError enum, with two variants:
-
LengthOne: to avoid removing from a NonEmpty of length 1 -
IndexOutOfBounds: for index larger than or equal to the length of the NonEmpty