From 8026ef1a04a6e26dea398858fa40f8e1207123a4 Mon Sep 17 00:00:00 2001 From: 132nd-Professor <132nd-Professor> Date: Mon, 7 Nov 2022 17:51:34 +0100 Subject: [PATCH] add blanket implementation for StringWriter --- src/writer.rs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/writer.rs b/src/writer.rs index 0c9dd8c..8b78466 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -48,10 +48,23 @@ fn create_zipwriter(outer_name: &str, inner_name: &str) -> Result>(&mut self, line: &S) -> Result<()>; +pub trait StringWriter +where + Self: Write, +{ + fn write_line(&mut self, line: &S) -> Result<()> + where + S: AsRef, + { + writeln!(self, "{}", line.as_ref()).with_context(|| "could not write line") + } - fn write_strings>(&mut self, lines: &[S]) -> Result<()>; + fn write_strings>(&mut self, lines: &[S]) -> Result<()> { + for line in lines { + self.write_line(line)?; + } + Ok(()) + } fn write_for_coalition>( &mut self, @@ -65,17 +78,6 @@ impl StringWriter for T where T: Write, { - fn write_line>(&mut self, line: &S) -> Result<()> { - writeln!(self, "{}", line.as_ref()).with_context(|| "could not write line") - } - - fn write_strings>(&mut self, lines: &[S]) -> Result<()> { - for line in lines { - self.write_line(line)?; - } - Ok(()) - } - fn write_for_coalition>( &mut self, lines: &[S],