Hacker News new | ask | show | jobs
by erkl 4059 days ago
Now, I'm not sure this is useful at all, but I think it would make sense for the value of an if-expression to be Option<T>.
1 comments

That might actually make sense... and I have to say that it would be useful, too. Quite often I find myself doing if condition { Some(foo) } else { None }; being able to just write if condition { foo } could be neat syntactic sugar for that (though it might also be confusing, since in Rust generally types don't form magically like that). The solution I'd come up with was just to give booleans a .then method (maybe they already have one that i missed).