Does rust provide call stack depth?

Background information: I have a function that calls itself both directly and indirectly with the help of other functions, and wants a cheap way to fail gracefully if the program ends from the call stack. I could handle the calls manually, but I would like to get a more elegant and reliable way to achieve this.

Is it possible to determine the current depth of the call stack using stable Rust?

The only options I could find are:

  • After the stack in ASM, but it requires instability and is not portable.
  • Using the GNU libc extension (backtrace). However, the backtrace is too wasteful and also not standard.
+4
source share
1 answer

The stacker box apparently provides the functionality you are looking for:

  • Function guaranteeing the amount of available stack
  • Function to request the amount of remaining stack that you could use for a subquery before the program actually overflows the stack

The library supports Linux, Windows, and macOS targets.

+2
source

Source: https://habr.com/ru/post/1684937/


All Articles