How to pass RUST_BACKTRACE=1 when running a Rust binary installed in Debian?

Just in case someone is looking for setting environment variable from source code, here is how you do it:

use std::env;
fn main() {
  // this method needs to be inside main() method
  env::set_var("RUST_BACKTRACE", "1");
}

The benefit of this approach — in contrast to manually setting the env variable from PowerShell– is that you won’t need to turn this variable off after you run this program. That is to say, ‘RUST_BACKTRACE=1’ is set only for this program, not others.

Leave a Comment

tech