optimization_tools/sudoku/
cell_val.rs1use derive_tools::Display;
2use derive_tools::{ Add, Sub, Mul, Div };
3
4#[ derive( Default, Debug, Display, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash ) ]
5#[ derive( Add, Sub, Mul, Div ) ]
6pub struct CellVal( u8 );
7
8impl CellVal
9{
10 #[ inline ]
11 pub fn unwrap( self ) -> u8
12 {
13 self.0
14 }
15}
16
17impl From< usize > for CellVal
18{
19 #[ inline ]
20 fn from( src : usize ) -> Self
21 {
22 debug_assert!( src < 10 );
23 Self ( src as u8 )
24 }
25}
26
27impl From< i32 > for CellVal
28{
29 #[ inline ]
30 fn from( src : i32 ) -> Self
31 {
32 debug_assert!( 0 <= src && src < 10 );
33 Self ( src as u8 )
34 }
35}
36
37impl From< u32 > for CellVal
38{
39 #[ inline ]
40 fn from( src : u32 ) -> Self
41 {
42 debug_assert!( src < 10 );
43 Self ( src as u8 )
44 }
45}
46
47impl From< u8 > for CellVal
48{
49 #[ inline ]
50 fn from( src : u8 ) -> Self
51 {
52 debug_assert!( src < 10 );
53 Self ( src )
54 }
55}
56
57impl From< CellVal > for usize
58{
59 #[ inline ]
60 fn from( src : CellVal ) -> Self
61 {
62 src.0 as usize
63 }
64}