If we use the ? at the end of the line, it returns the error if error happens. Is there a way to call one more function before returning the error ?
For now, I have to put the Result in a variable, call my function and just apply the "?" on my result to return if I got an error. Is there an easy way to do that ?
...
let result = my_call(param); // Return a result<(),error>
remove(param); // I can't return without running this function, this is why I didn't use ? before.
let _ = result?; // Just to return the error if I got an error on the call.
...
I don't mind if my_call got and error or not, I want to call my function "remove" before returning the function. Is there an elegant way to do that ? Thx
Result is an enum so you can just match the result. ? is syntactic sugar for the try! macro which is just a shortcut for matching on the enum (Error Handling - The Rust Programming Language)