diff --git a/src/fill/level.rs b/src/fill/level.rs index 284da90..414731a 100644 --- a/src/fill/level.rs +++ b/src/fill/level.rs @@ -23,7 +23,7 @@ mod test { fn sample() { let mode = LevelFillMode::new(); - assert_eq!(0.3, mode.sample(0.3, Vector::ZERO)); + assert_eq!(0.3, mode.sample(0.3, Vector::new(0.0, 0.0))); assert_eq!(0.7, mode.sample(0.7, Vector::new(0.1, 0.2))); } } \ No newline at end of file diff --git a/src/surface.rs b/src/surface.rs index d86385a..b0b1093 100644 --- a/src/surface.rs +++ b/src/surface.rs @@ -12,10 +12,9 @@ pub trait Surface { fn draw(&mut self, x: usize, y: usize, char: char, color: Color); fn clear(&mut self, x: usize, y: usize); fn present(&mut self) -> Result<(), Error>; - fn purge(&mut self) -> Result<(), Error>; } -pub struct WriteSurface { +pub struct WriteSurface { out: T, array: Array2D, } @@ -31,7 +30,7 @@ impl Default for Cell { fn default() -> Self { Cell::Keep } } -impl WriteSurface { +impl WriteSurface { pub fn new(out: T, width: usize, height: usize) -> Self { Self { out, @@ -87,10 +86,11 @@ impl Surface for WriteSurface { self.out.flush()?; Ok(()) } +} - fn purge(&mut self) -> Result<(), Error> { - self.out.execute(Clear(ClearType::Purge))?; - Ok(()) +impl Drop for WriteSurface { + fn drop(&mut self) { + self.out.execute(Clear(ClearType::Purge)).unwrap(); } } @@ -162,9 +162,9 @@ mod test { // Execute let data = Data::new(); let mock = MockWrite::new(data.clone()); - let mut renderer = WriteSurface::new(mock, 4, 4); + let renderer = WriteSurface::new(mock, 4, 4); - renderer.purge().unwrap(); + drop(renderer); // Recreate expectation let expected = Data::new();