qrlew 0.3.2

Sarus Qrlew Engine
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! # Debugging utilities
//!
// For debugging purpose
thread_local! {
    pub static DEPTH: std::cell::RefCell<u32>  = std::cell::RefCell::new(0);
}

pub fn debug<T, F: Fn() -> T>(name: &str, code: F) -> T {
    DEPTH.with(|depth| depth.replace_with(|old| *old + 1));
    println!(
        "Enterring {}, depth {}",
        name,
        DEPTH.with(|depth| depth.borrow().clone())
    );
    let result = code();
    DEPTH.with(|depth| depth.replace_with(|old| *old - 1));
    return result;
}