Skip to content

Instantly share code, notes, and snippets.

@solson
Last active April 13, 2016 03:17
Show Gist options
  • Save solson/094f7868b4959ba5d919 to your computer and use it in GitHub Desktop.
Save solson/094f7868b4959ba5d919 to your computer and use it in GitHub Desktop.
Rust code snippets
macro_rules! p {
($($e:expr),+) => ({
$(
println!("{} = {:?}", stringify!($e), $e);
)+
})
}
macro_rules! alias {
($name:ident = $e:expr) => (
macro_rules! $name {
() => ($e)
}
)
}
fn main() {
let a = 1;
let mut b = 2;
let c = 3;
alias!(f = a + b + c);
println!("{}", f!());
b = 10;
println!("{}", f!());
}
#[allow(non_camel_case_types)]
struct cout;
impl<T> std::ops::Shl<T> for cout {
type Output = cout;
fn shl(self, x: T) -> cout {
print!("{}", x);
cout
}
}
fn main() {
cout << "1 + 1 = " << 1 + 1 << '\n';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment