veho/columns/
setters.rs

1use crate::vector::zipeach;
2
3pub trait Setters<'a, T: 'a>: IntoIterator<Item=&'a mut Vec<T>>
4{
5    fn push_column<C>(self, column: C) where
6        Self: Sized,
7        C: IntoIterator<Item=T>
8    {
9        let rows = &mut self.into_iter();
10        zipeach(rows, column, |row, x| row.push(x));
11    }
12}
13
14impl<'a, M, T: 'a> Setters<'a, T> for M where
15    M: IntoIterator<Item=&'a mut Vec<T>>
16{}
17
18pub fn push_column<'a, M, C, T: 'a>(matrix: M, column: C) where
19    M: IntoIterator<Item=&'a mut Vec<T>>,
20    C: IntoIterator<Item=T>
21{ matrix.push_column(column) }
22
23#[cfg(test)]
24mod tests {
25    use crate::matrix::init;
26
27    use super::*;
28
29    #[test]
30    fn test_push_column() {
31        let mut matrix = init(3, 4, |i, j| ((i + 1) * 10 + (j + 1)) as i32);
32        println!(">> {:?}", &matrix);
33        (&mut matrix).push_column(vec![1, 2, 3]);
34        println!(">> {:?}", &matrix);
35    }
36}