Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- macro_rules! guard {
- ($o:expr) => {
- if let Some(x) = $o { x } else { return; }
- };
- ($o:expr, $body:block) => {
- if let Some(x) = $o { x } else { $body; return; }
- };
- }
- fn main() {
- let x = Some("hello");
- let y = guard!(x);
- println!("{}", y);
- let x = None;
- let y = guard!(x, {
- println!("Nothing to see here!");
- });
- println!("{:?}", y);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement