minesweeper: return empty vector if board has no rows
Otherwise, it will attempt to take the length of the first row, which
doesn't exist.
Needed because a no-rows case is tested in minesweeper 1.0.0
@@ -36,6 +36,9 @@ impl Board {
}
pub fn annotate(pieces: &[&str]) -> Vec<String> {
+ if pieces.len() == 0 {
+ return Vec::new();
+ }
let pieces_vec = pieces.iter().map(|&r| r.chars().collect()).collect();
Board {pieces: pieces_vec, num_rows: pieces.len(), num_cols: pieces[0].len()}.annotated()
}
