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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#![no_std]

#[macro_export]
macro_rules! dbgf {
    ($fmt: tt $(,)?) => {{
            extern crate std as __std;
            __std::eprintln!("[{}:{}:{}]", __std::file!(), __std::line!(), __std::column!())
    }};
    ($fmt: tt, $val:expr $(,)?) => {
        match $val {
            tmp => {{
                extern crate std as __std;
                __std::eprintln!(__std::concat!("[{}:{}:{}] {} = {:", $fmt, "}"),
                __std::file!(), __std::line!(), __std::column!(), __std::stringify!($val), &tmp);
                tmp
            }}
        }
    };
    ($fmt: tt $(, $val:expr)+ $(,)?) => {
        ($($crate::dbgf!($fmt, $val)),+,)
    };
}

#[cfg(test)]
mod tests {
    extern crate std as extern_std;

    use super::*;

    #[test]
    fn it_works() {
        #[derive(Debug, Clone)]
        struct S {
            i: extern_std::vec::Vec<f32>,
        }

        let s = S {
            i: extern_std::vec![11.0 / 3.0; 10],
        };
        extern_std::dbg!(&s, &s.i);
        dbgf!("5.3?", &s, &s.i);
    }
}