Say I have several functions that will return Result.
They have String Err but different Ok type.
I want to get ok value or print err message string and exit if there is an Err.
My code go like this:
let v1 = func1().unwrap_or_else( |err| {
eprintln!("[Error]: {}", err);
process::exit(1);
};
let v2 = func2().unwrap_or_else( |err| {
eprintln!("[Error]: {}", err);
process::exit(1);
};
// more functions like this
My question is how to reuse the print-and-exit code?
Function and closure will not work because the value's type in Ok is different.