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
use crate::algebra::abstr::{Field, Scalar};
use crate::algebra::linear::{Vector, Matrix};

pub struct MatrixRowIntoIterator<'a, T>
{
    m: &'a Matrix<T>,
    row: usize
}

impl<'a, T> MatrixRowIntoIterator<'a, T>
{
    pub fn new(m: &'a Matrix<T>) -> MatrixRowIntoIterator<'a, T>
    {
        MatrixRowIntoIterator{m, row: 0}
    }
}

impl<'a, T> Iterator for MatrixRowIntoIterator<'a, T> where T: Field + Scalar
{
    type Item = Vector<T>;

    // just return the str reference
    fn next(&mut self) -> Option<Self::Item>
    {
        if self.row < self.m.nrows()
        {
            let row: Vector<T> = self.m.get_row(self.row);
            self.row += 1;

            Some(row)
        }
        else {
            None
        }
    }
}