[Closed, with a new one] Checked exception simulation in Rust( 2nd version )

The idea for function syntax sugar has been discussed before, e.g. try fn

and


Note that previous proposals considered OK-Wrapping as an important feature.

The ?? syntax can't be used, because it's taken already: Ok(Ok(2))??; is valid today.

This seems to be very Result-specific. Currently ? is generic and supports other type like Option. Any "throw" syntax should probably be a lower-level concept that could also be mapped to custom enums, compose with async functions, etc.

Some form of ad-hoc enum may be useful, but it should also be a separate RFC. Rust tries to have orthogonal simple features that are building blocks for other features, not special-case ones (e.g. Rust has enum that allows making Option as a library feature, as opposed to nullable types in Swift which are built-in magic).

And logging is a completely separate thing. While logging is a commonly used functionality, I'm not sure if we've reached the point where we're certain enough of its implementation to cement it in the standard library. It's probably best to leave it out. It seems like a thing that can be easily added with traits without being built-in into the language.

1 Like