diff options
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)) } } |