I currently have the below code to handle the case where I want to handle an error without propagation or continue the function. The use case for this is a web server controller, where I would prefer to manual handle possible errors - which is why the return type is HttpResponse
.
I want to know if there is a way to do this without this unwrap
call as in my understanding the compiler should know there is a way to unwrap to a value at this point with no risk of panic.
// ...
let result: Result<u8, Error> = func_that_could_error();
if result.is_err() {
return HttpResponse::InternalServerError();
}
let value: u8 = result.unwrap();
// ...