Thatâs right, but thatâs also not subject of the discussion. My thesis is that return type of () turns a returning expression into imperative statement, since () represents void. And even if void is a value, itâs hard to say that itâs a result, since itâs useless.
It would know a concrete type I want.
Consider the following code:
option or Err(0);
It would be desugared:
match Or::into_option(option) {
Some(o) => From::from(o),
None => Err(0),
}
And then inlined:
match option {
Some(o) => Ok(o),
None => Err(0)
}
Or did you wanted to say that this couldnât happen?
Thatâs good point. I think that some trait bound on Or type parameter would be required to deny values that allocates in from function. Or we can use another trait instead.
That requires further investigationâŚ
Sometimes you need a more straightforward way to handle nullable values: option or value, option or next_option, option or resultâŚ
Handling nullable values in if and match expressions is less straightforward than could be with or.
Handling nullable with Option<T> combinators is less straightforward than with if and match.
Handling null as error using ? and try blocks is not straightforward at all.