How about `const Result:: OK = Result::Ok(())`?

Inspired by the proposed stabilization of ControlFlow::{BREAK, CONTINUE}`.

I agree with Mara that stabilizing these constants feels weird given that we don't have Result::OK either – but taking the contrapositive, perhaps the existence (and apparent usefulness) of these should be taken as an argument for adding (and eventually stabilizing) the OK constant as well? People tend to feel that the Ok(()) symbol soup is rather awkward, and being able to just write OK could alleviate the issue without going full implicit Ok wrapping.

try does do Ok-wrapping, though, which would reduce the need for this. I'd personally want to see that stabilized first to see if that addresses the need, before throwing something else at this.

Also, while Ok(()) is a little more verbose, it has the advantage of being something that uses components users already understand: if you know what Ok is, and you know what () is, then you know what Ok(()) is. OK doesn't benefit from that; it's a separate thing you have to know about, and put in your mental lexer, even though it looks like a typo.

10 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.