-
Notifications
You must be signed in to change notification settings - Fork 23
Description
Proposal
Problem statement
A non-panicking version of Vec::remove
is useful for code that does not want the risk of panicking or where the possibility of panicking should be clear from reading the source code.
Motivating examples or use cases
This is what is currently necessary:
if index < my_vector.len() { Some(my_vector.remove(index)) } else { None }
And this still links to the panic handler. The remove function already does a length check and can handle that case gracefully.
Solution sketch
Return an option and unwrap it in the panicking implementation.
It could be said that this implies all panicking functions should have non-panicking variants. I don't see a problem with that "counter" argument. I think they can be added as needed to make the effort smaller.
Alternatives
try_remove could be a wrapper around remove, but that seems wrong