I'm trying to return an Err
when any step of initialization returns an Err
:
fn init<'r>(&self) -> Result<(), ()> {
match self.check_1() {
Err(e) => return Err(e),
_ => {}
};
match self.check_2() {
Err(e) => return Err(e),
_ => {}
};
// [more checks]
return Ok(());
}
To me, this is cluttered. SQL has ifnull
or coalesce
which returns the first non-null result. As can be seen, I'm trying to do that, but return the first Err
.
Is there any syntax or macro that will enable me to return the first Err
encountered, while not executing subsequent check functions, i.e. short-circuiting the check evaluation logic?