Last active
April 13, 2016 03:17
-
-
Save solson/094f7868b4959ba5d919 to your computer and use it in GitHub Desktop.
Rust code snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| macro_rules! p { | |
| ($($e:expr),+) => ({ | |
| $( | |
| println!("{} = {:?}", stringify!($e), $e); | |
| )+ | |
| }) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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!()); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #[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