Is there a nice way to propagate errors in Rust? E. g., I'd like to refactor the following code to avoid nested errors:
.for_each(|record| {
match f1() {
Ok(a1) => match f2() {
Ok(a2) => match f3() {
Ok(_) => {}
Err(e) => {
eprintln!("Error: {}", e);
}
},
Err(e) => {
eprintln!("Error: {}", e);
}
},
Err(e) => {
eprintln!("Error: {}", e);
}
};
Ok(())
})
The question is not a duplicate because I've got a for_each
operator which complicates a situation for me. And when I put ?
to f2
I actually receive the following error:
the trait `std::convert::From<std::io::Error>` is not implemented for `grpcio::error::Error`