rune/
debug.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//! Debugging utilities.
use std::sync::atomic::{AtomicBool, Ordering};

static FLAG: AtomicBool = AtomicBool::new(false);

pub(crate) fn debug_enabled() -> bool {
    if cfg!(test) {
        true
    } else {
        FLAG.load(Ordering::Acquire)
    }
}

pub(crate) fn enable_debug() {
    FLAG.store(true, Ordering::Release);
}

pub(crate) fn disable_debug() {
    FLAG.store(false, Ordering::Release);
}

macro_rules! debug {
    ($($arg:tt)*) => {{
        if crate::debug::debug_enabled() {
            println!($($arg)*);
        }
    }}
}