Opposite of '?' - return early on success

72 points woollufff 33 comments

I'm loading parameters on startup. I test multiple locations for existence of environment variables, or content of file contained in environment, ​or variable in a ​configuration file which may be in multiple locations. What I want is an idiomatic way to really return a value upon first success; sort of the opposite of how ? unwraps and returns on failure.

It's there a better way than repeated if let Some(x)/Ok(x) return x