Hmm⌠-?> doesnât look all that weird to me⌠I think terseness here aids in bribing people away from .unwrap()âŚ
But hereâs perhaps a better idea:
Why not replicate the proposed throw / fail with succeed semantics intead?
So letâs introduce:
fail $expr <=> return <return_type>::from_error(From::from($expr))
and
pass $expr <=> return <return_type>::from_ok(From::from($expr))
// both fail and pass are 4 characters long, as a nice aesthetic bonus =P
By doing so, we donât have to change anything in the function signature, which is nice.
It also enables very local reasoning about the semantics.
Reworking the original example:
fn foo() -> Result<i32, Error> {
if bar() {
pass 0;
} else if baz() {
fail MyError;
}
quux()?;
pass 7
}
Some potential keywords instead of pass:
succeed
ok
deliver
-
triumph (OK; this is a jokeâŚ)
(yeah, I totally checked a dictionaryâŚ
)