1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//! a small macro-only crate providing ability to pretty-print a 2D nalgebra array

#[macro_export]
macro_rules! pretty_print {
    ($arr:expr) => {{
        let indent = 4;
        let prefix = String::from_utf8(vec![b' '; indent]).unwrap();
        let mut result_els = vec!["".to_string()];
        for i in 0..$arr.nrows() {
            let mut row_els = vec![];
            for j in 0..$arr.ncols() {
                row_els.push(format!("{:12.3}", $arr[(i,j)]));
            }
            let row_str = row_els.into_iter().collect::<Vec<_>>().join(" ");
            let row_str = format!("{}{}", prefix, row_str);
            result_els.push( row_str );
        }
        result_els.into_iter().collect::<Vec<_>>().join("\n")
    }}
}