For "loop unrolling" via declarative macros, is there something newer / better than rust - Can I create a macro that unrolls loops? - Stack Overflow ?
Technically, I need something stronger than merely "loop unrolling", so I have some "fragment" of the form:
i -> valid_rust_expr_containing_i
then I want this thing repeated with i=0, i=1, ..., i=n-1
You can do that with the seq-macro crate:
https://crates.io/crates/seq-macro/
Example:
use seq_macro::seq;
fn main(){
seq!(N in 0..=10 {
println!("{}", N);
});
}
prints:
0
1
2
3
4
5
6
7
8
9
10
It's a proc macro, don't know why it's a requirement that it must be a macro_rules! macro.
Good call. I meant (but failed) to express: "I'm okay with writing declarative macros; but prefer not to write proc macros if possible." However, it's fine if someone else has already written the procedural macro. 