call_depth

Macro call_depth 

Source
macro_rules! call_depth {
    () => { ... };
}
Expand description

Retrieves the current call depth of the function stack.

This macro returns an integer representing the depth of the function call stack at the point where it is invoked.

ยงExample

use iprint::call_depth;

fn main() {
    // Call depth here should be 0, since this is the main function.
    assert_eq!(call_depth!(), 0);

    // Call first_function(), this will increase the call depth.
    first_function();

    // Call depth here should be 0 again
    assert_eq!(call_depth!(), 0);
}

fn first_function() {
    // Call depth here should be 1, since we're one function deep from main.
    assert_eq!(call_depth!(), 1);

    // Call second_function(), this will increase the call depth.
    second_function();

    // Call depth here should be 1 again
    assert_eq!(call_depth!(), 1);
}

fn second_function() {
    // Call depth here should be 2, since we're two functions deep from main.
    assert_eq!(call_depth!(), 2);
}