Skip to content

Instantly share code, notes, and snippets.

@brson
Created September 13, 2012 02:22
Show Gist options
  • Save brson/3711448 to your computer and use it in GitHub Desktop.
Save brson/3711448 to your computer and use it in GitHub Desktop.
Rust keywords to macros
fn main() {
macro_rules! log_(
($lvl:expr, $msg:expr) => (
log($lvl, $msg)
);
);
macro_rules! assert_(
($pred:expr) => (
assert $pred
);
);
macro_rules! fail_(
($(e:expr)*) => (
fail $($e)*
);
);
log_!(error, "test");
assert_!(true);
assert_!(do task::try {
assert_!(true == false);
}.is_err());
do task::try {
fail_!()
}
do task::try {
fail_!(~"hey")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment