diff --git a/src/types.rs b/src/types.rs index 23e28ba1..d09ee716 100644 --- a/src/types.rs +++ b/src/types.rs @@ -176,7 +176,15 @@ impl DateTime { /// Indicates whether this date and time can be written to a zip archive. pub fn is_valid(&self) -> bool { - DateTime::from_date_and_time(self.year, self.month, self.day, self.hour, self.minute, self.second).is_ok() + DateTime::from_date_and_time( + self.year, + self.month, + self.day, + self.hour, + self.minute, + self.second, + ) + .is_ok() } #[cfg(feature = "time")] diff --git a/src/write.rs b/src/write.rs index 595a3e7c..7f0c0984 100644 --- a/src/write.rs +++ b/src/write.rs @@ -90,8 +90,8 @@ pub(crate) mod zip_writer { pub(super) comment: Vec, } } -pub use zip_writer::ZipWriter; use crate::write::GenericZipWriter::{Closed, Storer}; +pub use zip_writer::ZipWriter; #[derive(Default)] struct ZipWriterStats { @@ -959,15 +959,10 @@ impl GenericZipWriter { _ => {} } - match self { - Closed => { - return Err(io::Error::new( - io::ErrorKind::BrokenPipe, - "ZipWriter was already closed", - ) - .into()) - } - _ => {} + if let Closed = self { + return Err( + io::Error::new(io::ErrorKind::BrokenPipe, "ZipWriter was already closed").into(), + ); } let make_new_self: Box GenericZipWriter> = { @@ -990,27 +985,34 @@ impl GenericZipWriter { CompressionMethod::Deflated => { let level = clamp_opt( compression_level.unwrap_or(flate2::Compression::default().level() as i32), - deflate_compression_level_range() - ).ok_or(ZipError::UnsupportedArchive( + deflate_compression_level_range(), + ) + .ok_or(ZipError::UnsupportedArchive( "Unsupported compression level", ))? as u32; - Box::new(move |bare| - GenericZipWriter::Deflater(DeflateEncoder::new(bare, flate2::Compression::new(level))) - ) + Box::new(move |bare| { + GenericZipWriter::Deflater(DeflateEncoder::new( + bare, + flate2::Compression::new(level), + )) + }) } #[cfg(feature = "bzip2")] CompressionMethod::Bzip2 => { let level = clamp_opt( - compression_level - .unwrap_or(bzip2::Compression::default().level() as i32), - bzip2_compression_level_range(), - ).ok_or(ZipError::UnsupportedArchive( - "Unsupported compression level", - ))? as u32; - Box::new(move |bare| - GenericZipWriter::Bzip2(BzEncoder::new(bare, bzip2::Compression::new(level))) + compression_level.unwrap_or(bzip2::Compression::default().level() as i32), + bzip2_compression_level_range(), ) - }, + .ok_or(ZipError::UnsupportedArchive( + "Unsupported compression level", + ))? as u32; + Box::new(move |bare| { + GenericZipWriter::Bzip2(BzEncoder::new( + bare, + bzip2::Compression::new(level), + )) + }) + } CompressionMethod::AES => { return Err(ZipError::UnsupportedArchive( "AES compression is not supported for writing", @@ -1022,13 +1024,13 @@ impl GenericZipWriter { compression_level.unwrap_or(zstd::DEFAULT_COMPRESSION_LEVEL), zstd::compression_level_range(), ) - .ok_or(ZipError::UnsupportedArchive( - "Unsupported compression level", - ))?; - Box::new(move |bare| - GenericZipWriter::Zstd(ZstdEncoder::new(bare, level).unwrap() - )) - }, + .ok_or(ZipError::UnsupportedArchive( + "Unsupported compression level", + ))?; + Box::new(move |bare| { + GenericZipWriter::Zstd(ZstdEncoder::new(bare, level).unwrap()) + }) + } CompressionMethod::Unsupported(..) => { return Err(ZipError::UnsupportedArchive("Unsupported compression")) } @@ -1038,9 +1040,9 @@ impl GenericZipWriter { let bare = match mem::replace(self, Closed) { Storer(w) => w, #[cfg(any( - feature = "deflate", - feature = "deflate-miniz", - feature = "deflate-zlib" + feature = "deflate", + feature = "deflate-miniz", + feature = "deflate-zlib" ))] GenericZipWriter::Deflater(w) => w.finish()?, #[cfg(feature = "bzip2")] @@ -1052,7 +1054,7 @@ impl GenericZipWriter { io::ErrorKind::BrokenPipe, "ZipWriter was already closed", ) - .into()) + .into()) } }; *self = (make_new_self)(bare);