stack_algebra/
fmt.rs

1use core::fmt;
2
3use crate::Matrix;
4
5////////////////////////////////////////////////////////////////////////////////
6// Debug
7////////////////////////////////////////////////////////////////////////////////
8
9impl<T: fmt::Debug, const M: usize, const N: usize> fmt::Debug for Matrix<M, N, T> {
10    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11        if M == 1 || N == 1 {
12            f.debug_list().entries(self.iter()).finish()
13        } else {
14            fmt::Debug::fmt(&self.data, f)
15        }
16    }
17}
18
19impl<T: fmt::Display, const M: usize, const N: usize> fmt::Display for Matrix<M, N, T> {
20    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
21        writeln!(f, "\n")?;
22        for r in 0..M {
23            for c in 0..N {
24                writeln!(f, "{:2.11} ", self[(r, c)])?;
25            }
26            writeln!(f, "\n")?;
27        }
28        Ok(())
29    }
30}