Skip to content

Instantly share code, notes, and snippets.

@bvssvni
Created November 27, 2014 12:08
Show Gist options
  • Save bvssvni/d7a02cc89523be28b4c3 to your computer and use it in GitHub Desktop.
Save bvssvni/d7a02cc89523be28b4c3 to your computer and use it in GitHub Desktop.
current! {
FOO: bar
=> {
print_text();
print_text();
}
}
<current macros>:8:41: 8:43 error: expected ident, found =>
<current macros>:8 current!{ $($TAIL: $tail),* => $f:expr }
^~
#[macro_export]
macro_rules! current {
(=> $f:expr) => {{
$f
}};
($HEAD:ident: $head:ident $(,$TAIL:ident: $tail:ident)* => $f:expr) => {{
let $head = RefCell::new($head);
$HEAD.set(&$head, || {
current!{ $($TAIL: $tail),* => $f:expr }
})
}};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment