Replace dyn with generic

This commit is contained in:
Nicolas 2022-04-06 17:41:55 +02:00
parent d600c133bc
commit 7925af1bdc

View File

@ -15,8 +15,8 @@ pub trait Renderer {
fn purge(&mut self) -> Result<(), Error>; fn purge(&mut self) -> Result<(), Error>;
} }
pub struct WriteRenderer { pub struct WriteRenderer<T> {
out: Box<dyn Write>, out: T,
array: Array2D<Cell>, array: Array2D<Cell>,
} }
@ -31,8 +31,8 @@ impl Default for Cell {
fn default() -> Self { Cell::Keep } fn default() -> Self { Cell::Keep }
} }
impl WriteRenderer { impl<T> WriteRenderer<T> {
pub fn new(out: Box<dyn Write>, width: usize, height: usize) -> Self { pub fn new(out: T, width: usize, height: usize) -> Self {
Self { Self {
out, out,
array: Array2D::new(width, height) array: Array2D::new(width, height)
@ -40,7 +40,7 @@ impl WriteRenderer {
} }
} }
impl Renderer for WriteRenderer { impl<T: Write> Renderer for WriteRenderer<T> {
fn width(&self) -> usize { fn width(&self) -> usize {
self.array.width() self.array.width()
} }