Add clear
This commit is contained in:
parent
405f2fb1de
commit
8fc8e24335
1 changed files with 14 additions and 0 deletions
14
src/lib.rs
14
src/lib.rs
|
@ -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]];
|
||||||
|
|
Loading…
Reference in a new issue