1*8325e1ecSAlex Crichton use std::backtrace::Backtrace; 2*8325e1ecSAlex Crichton use std::sync::atomic::{AtomicBool, Ordering}; 3*8325e1ecSAlex Crichton 4*8325e1ecSAlex Crichton static ENABLED: AtomicBool = AtomicBool::new(true); 5*8325e1ecSAlex Crichton enabled() -> bool6*8325e1ecSAlex Crichtonfn enabled() -> bool { 7*8325e1ecSAlex Crichton ENABLED.load(Ordering::Relaxed) 8*8325e1ecSAlex Crichton } 9*8325e1ecSAlex Crichton 10*8325e1ecSAlex Crichton /// Forcibly disable capturing backtraces dynamically. 11*8325e1ecSAlex Crichton /// 12*8325e1ecSAlex Crichton /// XXX: This is only exposed for internal testing, to work around cargo 13*8325e1ecSAlex Crichton /// workspaces and feature resolution. This method may disappear or change 14*8325e1ecSAlex Crichton /// at any time. Instead of using this method, you should disable the 15*8325e1ecSAlex Crichton /// `backtrace` cargo feature. 16*8325e1ecSAlex Crichton #[doc(hidden)] disable_backtrace()17*8325e1ecSAlex Crichtonpub fn disable_backtrace() { 18*8325e1ecSAlex Crichton ENABLED.store(false, Ordering::Relaxed) 19*8325e1ecSAlex Crichton } 20*8325e1ecSAlex Crichton 21*8325e1ecSAlex Crichton #[track_caller] capture() -> Backtrace22*8325e1ecSAlex Crichtonpub fn capture() -> Backtrace { 23*8325e1ecSAlex Crichton if enabled() { 24*8325e1ecSAlex Crichton Backtrace::capture() 25*8325e1ecSAlex Crichton } else { 26*8325e1ecSAlex Crichton Backtrace::disabled() 27*8325e1ecSAlex Crichton } 28*8325e1ecSAlex Crichton } 29