We want to signify that it’s not a normal assignment. It’s an operation with two possibilities:
- Unwrapping on success or
- Return on error.
To me the following options read better:
Modifying the assignment operator
let Ok(user) ?= await fetchUser(id)
Modifying the right hand side expression of the assignment, which can either return a value or Error.
let Ok(user) = await fetchUser(id) ?
But that would mess with the ternary operator syntax.
Or like @hellos3b suggested, having the question mark on the unwrapper:
let Ok(user)? = await fetchUser(id)
The maybe keyword by @YKW is very appealing from a reader’s perspective as well.
I am not a fan of the let? as well - it lends a cryptic vibe to the language. We should strive to have an extremely readable syntax.