chj_util/
warn.rs

1//! Printing statements to stderr for debugging purposes
2
3#[macro_export]
4macro_rules! pp {
5    ($namestr:expr, $val:expr) => {{
6        let res = $val;
7        eprintln!("{}: {:?}", $namestr, res);
8        res
9    }}
10}
11
12#[macro_export]
13macro_rules! nopp {
14    ($namestr:expr, $arg:expr) => {
15        $arg
16    }
17}
18
19
20#[macro_export]
21macro_rules! warn {
22    ($formatstr:expr $(,$arg:expr)*) => { {
23        use std::io::Write;
24        let mut outp = std::io::BufWriter::new(std::io::stderr().lock());
25        let _ = write!(&mut outp, "W: ");
26        let _ = write!(&mut outp, $formatstr $(,$arg)*);
27        let _ = writeln!(&mut outp, " at {:?} line {}", file!(), line!());
28        let _ = outp.flush();
29    } }
30}
31
32#[macro_export]
33macro_rules! nowarn {
34    ($formatstr:expr $(,$arg:expr)*) => {
35    }
36}
37
38/// Requires a `pub static DO_WARN_THREAD: AtomicBool =
39/// AtomicBool::new(false);` in the scope, which can be changed via
40/// `...::DO_WARN_THREAD.store(true,
41/// std::sync::atomic::Ordering::SeqCst);`.
42#[macro_export]
43macro_rules! warn_thread {
44    { $fmt:expr $(,$arg:expr)* } => {
45        if DO_WARN_THREAD.load(std::sync::atomic::Ordering::SeqCst) {
46            use std::io::Write;
47            let mut outp = std::io::BufWriter::new(std::io::stderr().lock());
48            let _ = write!(&mut outp, "{:?} W: ", std::thread::current().id());
49            let _ = write!(&mut outp, $fmt $(,$arg)*);
50            let _ = writeln!(&mut outp, " at {:?} line {}", file!(), line!());
51            let _ = outp.flush();
52        }
53    }
54}
55
56#[macro_export]
57macro_rules! nowarn_thread {
58    ($formatstr:expr $(,$arg:expr)*) => {
59    }
60}
61
62
63#[macro_export]
64macro_rules! warn_todo {
65    ($formatstr:expr $(,$arg:expr)*) => {
66        use std::io::Write;
67        let mut outp = std::io::BufWriter::new(std::io::stderr().lock());
68        let _ = write!(&mut outp, "Todo: ");
69        let _ = write!(&mut outp, $formatstr, $(,$arg)*);
70        let _ = writeln!(&mut outp, " at {:?} line {}", file!(), line!());
71        let _ = outp.flush();
72    }
73}
74
75#[macro_export]
76macro_rules! nowarn_todo {
77    ($formatstr:expr $(,$arg:expr)*) => {
78    }
79}
80
81
82