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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use traits::{MatrixGet, MatrixElems, MatrixShape};
impl<T: MatrixGet<usize> + MatrixShape>
MatrixElems for
T
{
fn elems(self) -> MatrixElements<T>
{
MatrixElements::new(self)
}
}
#[derive(Copy, Clone)]
pub struct MatrixElements<T>
{
base: T,
idx: usize
}
impl<T: MatrixGet<usize> + MatrixShape>
MatrixElements<T>
{
pub fn new(base: T) -> MatrixElements<T>
{
MatrixElements{ base: base, idx: 0 }
}
}
impl<T: MatrixGet<usize> + MatrixShape>
Iterator for
MatrixElements<T>
{
type Item = f64;
fn next(&mut self) -> Option<f64>
{
let ret = if self.idx < self.base.len()
{
unsafe
{
Some(self.base.unsafe_get(self.idx))
}
}
else
{
None
};
self.idx += 1;
ret
}
}