|
|
|
|
|
by jchw
410 days ago
|
|
The reason it works this way is there's legitimately no easy way around it. You're not guaranteed a reasonable zero value for any type, so you can't do the slightly better Go thing (defined behavior but still wrong... Not great.) and you certainly can't do the Rust thing, because... There's no pattern matching. You can't conditionally enter a branch based on the presence of a value. There really is no reasonable workaround here, the language needs to be amended to make this safe and ergonomic. They tried to be cheeky with some of the other APIs, like std::variant, but really the best you can do is chuck the conditional branch into a lambda (or other function-based implementation of visitors) and the ergonomics of that are pretty unimpressive. Edit: but maybe fortune will change in the future, for anyone who still cares: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p26... |
|
This is one odd the major reasons I switched to rust, just to escape spending my whole life worrying about bugs caused by UB.