Pre-RFC: flexible `try fn`

For Return this changes

  • return Ok(x) into return x;
  • return Err(y) into throw y;

and to be honest I don’t really think that would be an improvement at all. This would create two different ways of doing things without becoming more readable or more ergonomic. This would also allow another thing before fn with would lead to things like unsafe const async try fn where it would be very hard to remember the order these things should go in.

To be honest I am against Ok wrapping in general because it reduces local reasoning and increases the complexity of the language just to save 4 characters, including the braces.

I also think that @repax’s named block proposal is a beter option than adding the try keyword mostly because it uses an existing underused language feature instead of adding an entirely new thing. It also really fits with the way other returns allow you to use labels.

12 Likes