diff --git a/src/formatter.rs b/src/formatter.rs index e7e135fdb..d66391329 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -65,9 +65,9 @@ impl FormatterFactory { FormatterFactory { kind } } - pub fn new_formatter<'output>( + pub fn new_formatter<'output, W: Write + 'output>( &self, - output: Box, + output: W, ) -> Box { match &self.kind { FormatterFactoryKind::PlainText => Box::new(PlainTextFormatter::new(output)), @@ -82,17 +82,17 @@ impl FormatterFactory { } } -pub struct PlainTextFormatter<'output> { - output: Box, +pub struct PlainTextFormatter { + output: W, } -impl<'output> PlainTextFormatter<'output> { - pub fn new(output: Box) -> PlainTextFormatter<'output> { +impl PlainTextFormatter { + pub fn new(output: W) -> PlainTextFormatter { Self { output } } } -impl Write for PlainTextFormatter<'_> { +impl Write for PlainTextFormatter { fn write(&mut self, data: &[u8]) -> Result { self.output.write(data) } @@ -102,7 +102,7 @@ impl Write for PlainTextFormatter<'_> { } } -impl Formatter for PlainTextFormatter<'_> { +impl Formatter for PlainTextFormatter { fn add_label(&mut self, _label: &str) -> io::Result<()> { Ok(()) } @@ -112,8 +112,8 @@ impl Formatter for PlainTextFormatter<'_> { } } -pub struct ColorFormatter<'output> { - output: Box, +pub struct ColorFormatter { + output: W, colors: Arc>, labels: Vec, cached_colors: HashMap, Vec>, @@ -248,11 +248,8 @@ fn config_colors(user_settings: &UserSettings) -> HashMap { result } -impl<'output> ColorFormatter<'output> { - pub fn new( - output: Box, - colors: Arc>, - ) -> ColorFormatter<'output> { +impl ColorFormatter { + pub fn new(output: W, colors: Arc>) -> ColorFormatter { ColorFormatter { output, colors, @@ -315,7 +312,7 @@ impl<'output> ColorFormatter<'output> { } } -impl Write for ColorFormatter<'_> { +impl Write for ColorFormatter { fn write(&mut self, data: &[u8]) -> Result { self.output.write(data) } @@ -325,7 +322,7 @@ impl Write for ColorFormatter<'_> { } } -impl Formatter for ColorFormatter<'_> { +impl Formatter for ColorFormatter { fn add_label(&mut self, label: &str) -> io::Result<()> { self.labels.push(label.to_owned()); let new_color = self.current_color();