From 0339ed27427ceeb06241cb29fa6de70acde8bc3b Mon Sep 17 00:00:00 2001 From: Mathijs van de Nes Date: Tue, 17 Mar 2015 17:06:32 +0100 Subject: [PATCH] Move the pattern matching of genericzipwriter --- src/write.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/write.rs b/src/write.rs index 563e4498..923e7804 100644 --- a/src/write.rs +++ b/src/write.rs @@ -71,23 +71,19 @@ impl Write for ZipWriter { if self.files.len() == 0 { return Err(io::Error::new(io::ErrorKind::Other, "No file has been started", None)) } self.stats.update(buf); - match self.inner + match self.inner.ref_mut() { - GenericZipWriter::Storer(ref mut w) => w.write(buf), - GenericZipWriter::Deflater(ref mut w) => w.write(buf), - GenericZipWriter::Bzip2(ref mut w) => w.write(buf), - GenericZipWriter::Closed => Err(io::Error::new(io::ErrorKind::BrokenPipe, "ZipWriter was already closed", None)), + Some(ref mut w) => w.write(buf), + None => Err(io::Error::new(io::ErrorKind::BrokenPipe, "ZipWriter was already closed", None)), } } fn flush(&mut self) -> io::Result<()> { - match self.inner + match self.inner.ref_mut() { - GenericZipWriter::Storer(ref mut w) => w.flush(), - GenericZipWriter::Deflater(ref mut w) => w.flush(), - GenericZipWriter::Bzip2(ref mut w) => w.flush(), - GenericZipWriter::Closed => Err(io::Error::new(io::ErrorKind::BrokenPipe, "ZipWriter was already closed", None)), + Some(ref mut w) => w.flush(), + None => Err(io::Error::new(io::ErrorKind::BrokenPipe, "ZipWriter was already closed", None)), } } } @@ -254,6 +250,15 @@ impl GenericZipWriter Ok(()) } + fn ref_mut(&mut self) -> Option<&mut Write> { + match *self { + GenericZipWriter::Storer(ref mut w) => Some(w as &mut Write), + GenericZipWriter::Deflater(ref mut w) => Some(w as &mut Write), + GenericZipWriter::Bzip2(ref mut w) => Some(w as &mut Write), + GenericZipWriter::Closed => None, + } + } + fn is_closed(&self) -> bool { match *self