With the reasoning that everything can be done with simple loops and if statements we'd never have any convenience methods at all My intention was to use my own perceived difficulty at implementing faulty iterators as an example and find out if there were something that can be improved on the language/stdlib level.
I do concede my point that Rust needs a harder treatment for errors, based on the examples in this thread. However there are still two things left that I feel can be improved:
-
try!
isn't usable insidenext()
— and I don't know what a good fix here might be for the general case. For now I'm content with my local variety of it. - There's no obvious iterator adaptor implementing the behaviour I'm after: yield an error and then stop. All suggested ways have slight warts on them, like
take_while
would swallow the error andfold_results
andcollect
require O(n) storage… However! I won't press this point any further as I can't really present a good convincing example, even for myself. Probably this use-case is indeed an edge case.