I found this question here but that one doesn't really answer my question due to it having an answer centered around unwrap_or_else.
Here is the code I am trying to use, simplified:
let x = loop {
// stuff
something.iter().map(|x| match x.fn_that_returns_result() {
Ok(_) => // snip,
Err(_) => {
// handle err;
continue;
}
})
break value;
}
The problem is that this won't compile, as I can't continue from a map. And I don't know any workarounds, as it's not like unwrap_or_else which is a wrapper around a match.
Is there any way to continue the outer loop from the map method call?
Resultwill short-circuit on the first failure.filter_mapand make your closure to wrap the return value inSome(..)on theOkcase and returnNoneon error. If I understand correctly what you are trying to do.mapandfilter(or justfilter_map) can do what you want, sometimes aforloop is just easier.