33 lines
822 B
Rust
33 lines
822 B
Rust
use bitmaps::Bitmap;
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub enum Square {
|
|
Value(u8),
|
|
Options(Bitmap<9>),
|
|
}
|
|
|
|
impl Square {
|
|
pub fn from_char(c: char) -> Square {
|
|
match c {
|
|
'1' => Square::Value(1),
|
|
'2' => Square::Value(2),
|
|
'3' => Square::Value(3),
|
|
'4' => Square::Value(4),
|
|
'5' => Square::Value(5),
|
|
'6' => Square::Value(6),
|
|
'7' => Square::Value(7),
|
|
'8' => Square::Value(8),
|
|
'9' => Square::Value(9),
|
|
'.' => Square::Options(Bitmap::mask(9)),
|
|
_ => panic!("Unexpected character in input: {}", c),
|
|
}
|
|
}
|
|
|
|
pub fn to_str(&self) -> String {
|
|
match self {
|
|
Square::Options(_) => " ".to_string(),
|
|
Square::Value(v) => v.to_string(),
|
|
}
|
|
}
|
|
}
|