Don't panic in VecInner::extend and return a Result#642
Don't panic in VecInner::extend and return a Result#642sirhcel wants to merge 1 commit intorust-embedded:mainfrom
Conversation
fcec20e to
28542e2
Compare
Other methods for extending VecInner already return results instead of panicking. In case of VecInner::extend, avoiding a panic by checking that the actual amount of elements to extend with fits beforehand is not generally possible. So attempt to add the elements from the iterator and restore the original length in case of an error.
28542e2 to
f6f8aa5
Compare
|
This goes hand in hand with the panicking There was some discussion of the topic in #442. My opinion is that for the next breaking release we should aim to remove implicitly panicking APIs. |
Thank you for the references! The latter is a great read on the pros and cons. Do you mean the former in the sense that there should be a fallible conversion like
I would prefer this too. Especially for operations involving iterators where getting to know the actual length/number of items to return look non-trivial to me and opting in to panicking with unwrapping the result seems way less annoying to me than writing all the pre-checks for ensuring that an operation won't panic. |
Other methods for extending VecInner already return results instead of panicking. In case of VecInner::extend, avoiding a panic by checking that the actual amount of elements to extend with fits beforehand is not generally possible.
So attempt to add the elements from the iterator and restore the original length in case of an error.
This is a semver-breaking change.