macro_rules! inspect { ($prefix:expr => $expr:expr) => { ... }; ($expr:expr) => { ... }; ($prefix:expr => $($expr:expr),+) => { ... }; ($($expr:expr),+) => { ... }; }
Expand description
Evaluates an expression, prints a stringified version of the expression along with the evaluated value, and then returns that value.
§Example
fn lcm_2_to_4() -> u32 {
let mut i = 1;
loop {
if inspect!(i % 2, i % 3, i % 4) == (0, 0, 0) {
return inspect!("done: i = " => i);
}
i += 1;
}
}
assert_eq!(lcm_2_to_4(), 12);
Returns 12
, and prints the following to stdout:
ⓘ
src/inspect.rs:94 - (i % 2, i % 3, i % 4) = (1, 1, 1)
src/inspect.rs:94 - (i % 2, i % 3, i % 4) = (0, 2, 2)
src/inspect.rs:94 - (i % 2, i % 3, i % 4) = (1, 0, 3)
src/inspect.rs:94 - (i % 2, i % 3, i % 4) = (0, 1, 0)
src/inspect.rs:94 - (i % 2, i % 3, i % 4) = (1, 2, 1)
src/inspect.rs:94 - (i % 2, i % 3, i % 4) = (0, 0, 2)
src/inspect.rs:94 - (i % 2, i % 3, i % 4) = (1, 1, 3)
src/inspect.rs:94 - (i % 2, i % 3, i % 4) = (0, 2, 0)
src/inspect.rs:94 - (i % 2, i % 3, i % 4) = (1, 0, 1)
src/inspect.rs:94 - (i % 2, i % 3, i % 4) = (0, 1, 2)
src/inspect.rs:94 - (i % 2, i % 3, i % 4) = (1, 2, 3)
src/inspect.rs:94 - (i % 2, i % 3, i % 4) = (0, 0, 0)
src/inspect.rs:95 - done: i = 12