From 70315e4652bb49981108a9b920b95ab82a53edb7 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 28 Jan 2023 01:01:15 +0300 Subject: feat: interactively play in main loop --- src/square.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/square.rs') 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 { 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)) } } -- cgit v1.2.3