title: How to get the current stack frame depth in Rust?
body: <p>How do I determine the current stack frame depth?</p>
  <pre class="lang-rust prettyprint-override"><code>fn print_depths() {
      println!(&quot;stack frame depth {}&quot;, stack_frame_depth());
      fn print_depth2() {
          println!(&quot;stack frame depth {}&quot;, stack_frame_depth());
      }
      print_depth2();
  }
  
  pub fn main() {
      print_depths();
  }
  </code></pre>
  <p>would print</p>
  <pre class="lang-none prettyprint-override"><code>stack frame depth 1
  stack frame depth 2
  </code></pre>
  <br />
  <p>I know <code>main</code> has callers so the particular numbers might be different.</p>
  <br />
  <p>I have tried <a href="https://docs.rs/stacker/0.1.13/stacker/fn.remaining_stack.html" rel="nofollow noreferrer"><code>stacker::remaining_stack</code></a>. However, that prints a count of bytes remaining in the stack. Since the arguments passed to a function affect the stack byte &quot;height&quot; then it is not possible to derive a simple function call &quot;height&quot;. I want a count of the current function call height.</p>