array_matrix/matrix/
diag.rs

1pub trait Diag
2{
3    type Output;
4    
5    /// Returns the diagonal of the given matrix
6    /// 
7    /// {aᵢᵢ}
8    /// 
9    /// # Examples
10    /// 
11    /// ```rust
12    /// let a = [
13    ///     [1.0, 2.0],
14    ///     [3.0, 4.0]
15    /// ];
16    /// assert_eq!(a.diag(), [1.0, 4.0]);
17    /// ```
18    fn diag(&self) -> Self::Output;
19}
20
21impl<F, const L: usize, const H: usize> Diag for [[F; L]; H]
22where F: Clone
23{
24    type Output = Vec<F>;
25    fn diag(&self) -> Self::Output
26    {
27        (0..L.min(H)).map(|i| self[i][i].clone()).collect()
28    }
29}