dbgf/
lib.rs

1#![no_std]
2
3#[macro_export]
4macro_rules! dbgf {
5    ($fmt: tt $(,)?) => {{
6            extern crate std as __std;
7            __std::eprintln!("[{}:{}:{}]", __std::file!(), __std::line!(), __std::column!())
8    }};
9    ($fmt: tt, $val:expr $(,)?) => {
10        match $val {
11            tmp => {{
12                extern crate std as __std;
13                __std::eprintln!(__std::concat!("[{}:{}:{}] {} = {:", $fmt, "}"),
14                __std::file!(), __std::line!(), __std::column!(), __std::stringify!($val), &tmp);
15                tmp
16            }}
17        }
18    };
19    ($fmt: tt $(, $val:expr)+ $(,)?) => {
20        ($($crate::dbgf!($fmt, $val)),+,)
21    };
22}
23
24#[cfg(test)]
25mod tests {
26    extern crate std as extern_std;
27
28    use super::*;
29
30    #[test]
31    fn it_works() {
32        #[derive(Debug, Clone)]
33        struct S {
34            i: extern_std::vec::Vec<f32>,
35        }
36
37        let s = S {
38            i: extern_std::vec![11.0 / 3.0; 10],
39        };
40        extern_std::dbg!(&s, &s.i);
41        dbgf!("5.3?", &s, &s.i);
42    }
43}