I am trying to write a macro in time, how long have the various functions performed.
macro_rules! timer {
($( $x: expr ),+ ) => {
let now = SystemTime::now();
let val = $x;
match now.elapsed() {
Ok(elapsed) => {
println!("{}", elapsed.as_secs());
}
Err(e) => {
println!("{:?}", e);
}
}
val
}
}
but the compiler produces a error: variable 'x' is still repeating at this depth.
In another statically typed language, I tried this in (F #) using closure - this was the easiest approach. Is it impossible to have such a common movie in Rust?
wegry source
share