mirror of
https://github.com/ricoriedel/wipe.git
synced 2024-11-23 00:16:38 +00:00
Replace finish with drop
This commit is contained in:
parent
71e531a276
commit
8b551c3d1c
@ -9,7 +9,6 @@ use mockall::automock;
|
|||||||
pub trait Renderer {
|
pub trait Renderer {
|
||||||
fn render(&mut self, step: f32);
|
fn render(&mut self, step: f32);
|
||||||
fn present(&mut self) -> Result<(), Error>;
|
fn present(&mut self) -> Result<(), Error>;
|
||||||
fn finish(&mut self) -> Result<(), Error>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SamplerRenderer<TSurface, TSampler> {
|
pub struct SamplerRenderer<TSurface, TSampler> {
|
||||||
@ -42,10 +41,6 @@ impl<T1: Surface, T2: Sampler> Renderer for SamplerRenderer<T1, T2> {
|
|||||||
fn present(&mut self) -> Result<(), Error> {
|
fn present(&mut self) -> Result<(), Error> {
|
||||||
self.surface.present()
|
self.surface.present()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn finish(&mut self) -> Result<(), Error> {
|
|
||||||
self.surface.finish()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -91,16 +86,4 @@ mod test {
|
|||||||
|
|
||||||
renderer.present().unwrap();
|
renderer.present().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn finish() {
|
|
||||||
let mut surface = MockSurface::new();
|
|
||||||
let sampler = MockSampler::new();
|
|
||||||
|
|
||||||
surface.expect_finish().once().returning(|| Ok(()));
|
|
||||||
|
|
||||||
let mut renderer = SamplerRenderer::new(surface, sampler);
|
|
||||||
|
|
||||||
renderer.finish().unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -26,7 +26,7 @@ impl<T1: Timer, T2: Renderer> Runner<T1, T2> {
|
|||||||
self.renderer.present()?;
|
self.renderer.present()?;
|
||||||
self.timer.sleep();
|
self.timer.sleep();
|
||||||
}
|
}
|
||||||
self.renderer.finish()
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,8 +59,6 @@ mod test {
|
|||||||
renderer.expect_present().once().in_sequence(seq).returning(|| Ok(()));
|
renderer.expect_present().once().in_sequence(seq).returning(|| Ok(()));
|
||||||
timer.expect_sleep().once().in_sequence(seq).return_const(());
|
timer.expect_sleep().once().in_sequence(seq).return_const(());
|
||||||
|
|
||||||
renderer.expect_finish().once().in_sequence(seq).returning(|| Ok(()));
|
|
||||||
|
|
||||||
let runner = Runner::new(Duration::from_secs(4), timer, renderer);
|
let runner = Runner::new(Duration::from_secs(4), timer, renderer);
|
||||||
|
|
||||||
runner.run().unwrap();
|
runner.run().unwrap();
|
||||||
|
@ -14,7 +14,6 @@ pub trait Surface {
|
|||||||
fn draw(&mut self, x: usize, y: usize, char: char, color: Color);
|
fn draw(&mut self, x: usize, y: usize, char: char, color: Color);
|
||||||
fn clear(&mut self, x: usize, y: usize);
|
fn clear(&mut self, x: usize, y: usize);
|
||||||
fn present(&mut self) -> Result<(), Error>;
|
fn present(&mut self) -> Result<(), Error>;
|
||||||
fn finish(&mut self) -> Result<(), Error>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WriteSurface<T: Write> {
|
pub struct WriteSurface<T: Write> {
|
||||||
@ -89,10 +88,13 @@ impl<T: Write> Surface for WriteSurface<T> {
|
|||||||
self.out.flush()?;
|
self.out.flush()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn finish(&mut self) -> Result<(), Error> {
|
impl<T: Write> Drop for WriteSurface<T> {
|
||||||
self.out.execute(Clear(ClearType::Purge))?;
|
fn drop(&mut self) {
|
||||||
Ok(())
|
if let Err(e) = self.out.execute(Clear(ClearType::Purge)) {
|
||||||
|
println!("{}", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,25 +161,6 @@ mod test {
|
|||||||
assert_eq!(8, renderer.height());
|
assert_eq!(8, renderer.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn finish() {
|
|
||||||
// Execute
|
|
||||||
let data = Data::new();
|
|
||||||
let mock = MockWrite::new(data.clone());
|
|
||||||
let mut renderer = WriteSurface::new(mock, 4, 4);
|
|
||||||
|
|
||||||
renderer.finish().unwrap();
|
|
||||||
|
|
||||||
// Recreate expectation
|
|
||||||
let expected = Data::new();
|
|
||||||
let mut stream = MockWrite::new(expected.clone());
|
|
||||||
|
|
||||||
stream.execute(Clear(ClearType::Purge)).unwrap();
|
|
||||||
|
|
||||||
// Compare
|
|
||||||
assert_eq!(expected, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn present() {
|
fn present() {
|
||||||
// Execute
|
// Execute
|
||||||
|
Loading…
Reference in New Issue
Block a user