I have number of source files (001.rs, 002.rs, 003.rs, ...), each having the following content:
// FILE: 001.rs
pub const NUM: i64 = 1; // Different number per file
I would like to load all these values with a macro:
// FILE: main.rs
macro_rules! get_numbers_from_modues {
($start: expr, $end: expr) => {{
let mut numbers = std::vec::Vec::<i64>::with_capacity($end - $start);
for i in $start..=$end {
#[path = format!("{:03}.rs", i)] // <= error: unexpected token: `format`
mod inline_module;
numbers.push(inline_module::NUM);
}
numbers
}};
}
fn main() {
let numbers = get_numbers_from_modues!(1, 2);
}
This doesn't compile as the path
attribute had an unexpected token. Is there a way to set the attribute in a procedural way? All values are known at compile time.
This is a minimal example, there is more than the number in each file and I can't change the structure. I would simply prefer to not repeat myself for all the cases.