diff --git a/src/compression.rs b/src/compression.rs index f34e2b3c..3c607195 100644 --- a/src/compression.rs +++ b/src/compression.rs @@ -2,6 +2,7 @@ use std::fmt; +#[allow(deprecated)] /// Compression methods for the contents of a ZIP file. #[derive(Copy, Clone, PartialEq, Debug)] pub enum CompressionMethod { @@ -28,13 +29,14 @@ impl CompressionMethod { note = "implementation details are being removed from the public API" )] pub fn from_u16(val: u16) -> CompressionMethod { + #[allow(deprecated)] match val { 0 => CompressionMethod::Stored, #[cfg(feature = "deflate")] 8 => CompressionMethod::Deflated, #[cfg(feature = "bzip2")] 12 => CompressionMethod::Bzip2, - #[allow(deprecated)] + v => CompressionMethod::Unsupported(v), } } @@ -45,13 +47,13 @@ impl CompressionMethod { note = "implementation details are being removed from the public API" )] pub fn to_u16(self) -> u16 { + #[allow(deprecated)] match self { CompressionMethod::Stored => 0, #[cfg(feature = "deflate")] CompressionMethod::Deflated => 8, #[cfg(feature = "bzip2")] CompressionMethod::Bzip2 => 12, - #[allow(deprecated)] CompressionMethod::Unsupported(v) => v, } } diff --git a/src/write.rs b/src/write.rs index f1d762dd..5468a286 100644 --- a/src/write.rs +++ b/src/write.rs @@ -397,20 +397,22 @@ impl GenericZipWriter { } }; - *self = match compression { - CompressionMethod::Stored => GenericZipWriter::Storer(bare), - #[cfg(feature = "deflate")] - CompressionMethod::Deflated => GenericZipWriter::Deflater(DeflateEncoder::new( - bare, - flate2::Compression::default(), - )), - #[cfg(feature = "bzip2")] - CompressionMethod::Bzip2 => { - GenericZipWriter::Bzip2(BzEncoder::new(bare, bzip2::Compression::Default)) - } + *self = { #[allow(deprecated)] - CompressionMethod::Unsupported(..) => { - return Err(ZipError::UnsupportedArchive("Unsupported compression")) + match compression { + CompressionMethod::Stored => GenericZipWriter::Storer(bare), + #[cfg(feature = "deflate")] + CompressionMethod::Deflated => GenericZipWriter::Deflater(DeflateEncoder::new( + bare, + flate2::Compression::default(), + )), + #[cfg(feature = "bzip2")] + CompressionMethod::Bzip2 => { + GenericZipWriter::Bzip2(BzEncoder::new(bare, bzip2::Compression::Default)) + } + CompressionMethod::Unsupported(..) => { + return Err(ZipError::UnsupportedArchive("Unsupported compression")) + } } }; diff --git a/tests/end_to_end.rs b/tests/end_to_end.rs index cf5986bb..6268920a 100644 --- a/tests/end_to_end.rs +++ b/tests/end_to_end.rs @@ -39,7 +39,7 @@ fn read_zip_file(zip_file: &mut Cursor>) -> zip::result::ZipResult>(); assert_eq!(file_names, expected_file_names);