Module iterators

Module iterators 

Source
Expand description

This module contains structs for iterating over matrices.

Some of these structs also implement Index allowing you to use the container[index] notation.

§Examples

use matrixable::MatrixExt;

let m = [
    ['a', 'b', 'c'],
    ['d', 'e', 'f'],
    ['g', 'h', 'i']
];

{
    let row = m.row(0).unwrap();
    assert_eq!('a', row[0]);
    assert_eq!('b', row[1]);
    assert_eq!('c', row[2]);
}
 
{
    let col = m.col(1).unwrap();
    assert_eq!('b', col[0]);
    assert_eq!('e', col[1]);
    assert_eq!('h', col[2]);
}
 
{
    let diag = m.diag(2).unwrap();
    assert_eq!('a', diag[0]);
    assert_eq!('e', diag[1]);
    assert_eq!('i', diag[2]); 
}
 
let m = [['r', 'i', 'o']];
let it = m.iter();
 
assert_eq!('r', it[0]);
assert_eq!('i', it[1]);
assert_eq!('o', it[2]); 

It may happen you just need a unique element. In that case you will rather use .nth() from the standard Iterator trait.

use matrixable::MatrixMutExt;

let mut m = [
    ['a', 'b', 'c'],
    ['d', 'e', 'f'],
    ['g', 'h', 'i']
];
 
let h = m.row_mut(2).unwrap().nth(1).unwrap();
// Or 
//    = m.rows_mut().nth(2).unwrap().nth(1).unwrap();
 
assert_eq!(&mut 'h', h);
 
*h = 'z';
 
assert_eq!(Some(&mut 'z'), m.row_mut(2).unwrap().nth(1));

Structs§

Column
An iterator over a matrix column.
ColumnMut
An iterator over a mutable matrix column.
Columns
ColumnsMut
Diag
An iterator over a matrix diagonal.
DiagMut
An iterator over a mutable matrix diagonal.
Diags
DiagsMut
Enumerator
An iterator that yields an element of the a matrix-like struct along with the subscripts of that element.
IntoAxes
Iter
An iterator over the elements of the matrix.
IterMut
An iterator over the elements of the matrix (mutable).
Row
An iterator over a matrix row.
RowMut
An iterator over a mutable matrix row.
Rows
RowsMut