Skip to content

Instantly share code, notes, and snippets.

@gsquire
Created August 19, 2016 16:35
Show Gist options
  • Save gsquire/44b63b8e9c8cf2daa726cbcf84cd8cf2 to your computer and use it in GitHub Desktop.
Save gsquire/44b63b8e9c8cf2daa726cbcf84cd8cf2 to your computer and use it in GitHub Desktop.
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