Created
August 19, 2016 16:35
-
-
Save gsquire/44b63b8e9c8cf2daa726cbcf84cd8cf2 to your computer and use it in GitHub Desktop.
This file contains 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! join { | |
($($s:expr),+) => ({ | |
let mut agg = String::new(); | |
$(agg.push_str($s);)* | |
agg | |
}); | |
} | |
macro_rules! repeat { | |
($s:expr, $n:expr) => ({ | |
let size = $s.len(); | |
let mut agg = String::with_capacity(size * $n); | |
for _ in 0..$n { | |
agg.push_str($s); | |
} | |
agg | |
}); | |
} | |
fn main() { | |
println!("{}", repeat!("garrett", 7)); | |
println!("{}", join!("a", "b", "c")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment