I'm looking for a more concise way to check if a function that returns a Result
succeeded or not. Currently, I'm using a combination of map_err
and ok
to check for errors and ignore the successful result. However, this approach can be verbose and hard to read.
Is there an idiomatic way in Rust to check if a Result
-returning function failed or not without resorting to match
statements? I'm open to any suggestions that can make the code more concise and easier to read.
...
myexe::testing_func(&worker)
.map_err(|e| {
error(format!("Failed to blabla: {}", e));
std::process::exit(1);
})
.ok();
...