Add clear

This commit is contained in:
Armin Becher 2020-04-05 15:19:19 +02:00
parent 405f2fb1de
commit 8fc8e24335

View file

@ -195,6 +195,13 @@ impl<T: Clone> Grid<T> {
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
self.cols == 0 && self.rows == 0 self.cols == 0 && self.rows == 0
} }
/// Clears the grid.
pub fn clear(&mut self) {
self.rows = 0;
self.cols = 0;
self.data.clear();
}
} }
impl<T: Clone> Clone for Grid<T> { impl<T: Clone> Clone for Grid<T> {
@ -245,6 +252,13 @@ impl<T: fmt::Debug> fmt::Debug for Grid<T> {
mod test { mod test {
use super::*; use super::*;
#[test]
fn clear() {
let mut grid: Grid<u8> = grid![[1, 2, 3]];
grid.clear();
assert!(grid.is_empty());
}
#[test] #[test]
fn is_empty_false() { fn is_empty_false() {
let grid: Grid<u8> = grid![[1, 2, 3]]; let grid: Grid<u8> = grid![[1, 2, 3]];