For the mostpart, Rust error handling is okay. What really rustles my jimmies, however, is the often mandatory indentation because of a lack of an inverse "if let". I prefer to bail out of a block if a condition is NOT met, rather than execute another nested block if it IS met. Rust makes that harder than it should be. It's good code hygiene in every other language, and Rust makes it painful in places. I've even been…
guard let value = optvalue else {
return // optvalue is none
}
There has been several proposals [2][3] to fix it in Rust but they don't seem to go anywhere.I'm using this in my own code now to unwrap or return (it looks stupid):
let value = if let Some(value) = optvalue {
value
} else { // optvalue is none
return;
};
[1] https://szymonkrajewski.pl/why-should-you-return-early/