error handling for position

This commit is contained in:
Max Bradbury 2020-04-14 00:37:02 +01:00
parent 5d1c515192
commit 389cfe5f10
1 changed files with 5 additions and 0 deletions

View File

@ -9,6 +9,11 @@ impl From<String> for Position {
// e.g. "2,5"
let xy: Vec<&str> = string.split(',').collect();
let x = xy[0].parse().unwrap();
if xy.len() < 2 {
panic!("Bad position : {}", string);
}
let y = xy[1].parse().unwrap();
Position { x, y }