diff options
Diffstat (limited to 'src/writer.rs')
-rw-r--r-- | src/writer.rs | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/src/writer.rs b/src/writer.rs index cf30ee7..3b9e710 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -1,27 +1,24 @@ -use std::io::{BufWriter, LineWriter, Write}; +use std::io::{self, BufWriter, LineWriter, Write}; use crate::config::Config; use crate::writeable::Writeable; pub trait WriteReceiver: Write { - fn write_choice<Wa: Writeable>(&mut self, b: Wa, config: &Config, print_separator: bool) { - let num_bytes_written = match self.write(&b.to_byte_buf()) { - Ok(x) => x, - Err(e) => { - eprintln!("Failed to write to output: {}", e); - 0 - } - }; + fn write_choice<Wa: Writeable>( + &mut self, + b: Wa, + config: &Config, + print_separator: bool, + ) -> io::Result<()> { + let num_bytes_written = self.write(&b.to_byte_buf())?; if num_bytes_written > 0 && print_separator { - self.write_separator(config); + self.write_separator(config)?; }; + Ok(()) } - fn write_separator(&mut self, config: &Config) { - match self.write(&config.output_separator) { - Ok(_) => (), - Err(e) => eprintln!("Failed to write to output: {}", e), - } + fn write_separator(&mut self, config: &Config) -> io::Result<()> { + self.write(&config.output_separator).map(|_| ()) } } |