if $c:expr { Some($r:expr) } else { None }
$c.then(|| $r)
For more information about how rustc works, see the rustc dev guide.