Question:
I know that when handling errors usingResult
and Option
, it can be expressed more concisely by using unwrap_or_else
, unwrap_or_default
, etc. instead of match
.The following is an example of expressing the match expression more concisely using
unwrap
.Questions
Is there a function I can use instead of
match
if I want to put a return
statement instead of putting a different value when an error occurs?Answer:
You can use a combination ofmap_err()
and the error propagation operator ?
:If you have better answer, please add a comment about this, thank you!