diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-01-28 01:01:15 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-01-28 01:01:15 +0300 |
commit | 70315e4652bb49981108a9b920b95ab82a53edb7 (patch) | |
tree | f0bb316ebd5fface6f01aa164bf29afd7e4d6495 /src/square.rs | |
parent | 690af97aa6c49a8ad76e47a2cee0c0b23b84ae6e (diff) | |
download | chessnost-70315e4652bb49981108a9b920b95ab82a53edb7.tar.gz |
feat: interactively play in main loop
Diffstat (limited to 'src/square.rs')
-rw-r--r-- | src/square.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/square.rs b/src/square.rs index f26ed4d..e518a92 100644 --- a/src/square.rs +++ b/src/square.rs @@ -52,7 +52,7 @@ impl Square { Self::from(*self as u8 + 1) } - pub fn from_notation(chars: &mut Chars) -> Self { + pub fn from_notation(chars: &mut Chars) -> Result<Self, String> { let file = match chars.next() { Some(ch) => { match ch { @@ -64,22 +64,22 @@ impl Square { 'f' => 5, 'g' => 6, 'h' => 7, - _ => panic!("Incorrect file!") + _ => return Err(String::from("Incorrect file!")) } }, - None => panic!("Missing file"), + None => return Err(String::from("Missing file")) }; let rank = match chars.next() { Some(ch) => { match ch.to_digit(10) { Some(digit) => digit - 1, - None => panic!("Incorrect rank") + None => return Err(String::from("Incorrect rank")) } } - None => panic!("Missing rank") + None => return Err(String::from("Missing rank")) }; - Self::from_coords(rank as u8, file) + Ok(Self::from_coords(rank as u8, file)) } } |