Not proud of this answer :D but I wanted to to give a different perspective.
By using macro-rules, you can easily define static concatenation by composition. In this case, I define 100 * str = 4 * 25 * str = 4 * 5 * 5 * str. You could also do 100 * str = 10 * 10 * str, in less lines (but more columns :))
macro_rules! rep {
($t:expr, 4) => { concat!($t, $t, $t, $t) };
($t:expr, 5) => { concat!($t, $t, $t, $t, $t) };
($t:expr, 25) => { rep!(rep!($t, 5), 5) };
($t:expr, 100) => { rep!(rep!($t, 25), 4) };
}
fn main() {
assert_eq!(rep!("x", 100).len(), 100);
}
Since macros work on language elements, it's not possible to use a counter and simple recursively call the macro like this:
macro_rules! does_not_work {
($t:expr, 1) => { $t };
($t:expr, $n:) => { concat!($t, does_not_work!($t, $n-1)) };
}
But recursively composing the macro should do the trick in this simple case. I didn't try using different macro_rules patterns or other kind of macros, but it should be possible to do something more elegant.