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
55
56
57
58
59
60
61
62
63
64
use std::fmt;
use veho::matrix::Matrix;
use veho::vector::Mappers;
use crate::utils::option_to_string;
pub struct BoundMatrix<T> {
pub body: Matrix<Option<T>>,
pub min: Option<T>,
pub max: Option<T>,
pub count: usize,
}
impl<T> fmt::Display for BoundMatrix<T> where T: fmt::Display {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{{ \n body: {}, \n min: {}, \n max: {}, \n count: {} \n}} ",
format!("[ \n{} \n]", (&self.body).mapper(|row| {
format!(" [ {} ],", row.mapper(option_to_string).join(", "))
}).join("\n")),
option_to_string(&self.min),
option_to_string(&self.max),
&self.count
)
}
}
impl<T> BoundMatrix<T> {
}
#[cfg(test)]
mod tests {
use veho::matrix::{iso, zipper};
use super::*;
#[test]
fn test() {
let mx = [
[Some(2), None, None, None],
[None, Some(0), None, None],
[None, None, Some(6), None],
[None, None, None, Some(1)],
];
let mut bound_matrix = BoundMatrix {
body: iso(4, 4, None),
min: None,
max: None,
count: 0,
};
let holder_matrix = &mut bound_matrix.body;
zipper(holder_matrix, &mx, |holder, val| {
match val {
None => {}
Some(v) => { *holder = Some(v) }
}
});
println!("{}", bound_matrix);
}
}