From e43ac72f7df8d58f909bbdd2cb42af5182b64295 Mon Sep 17 00:00:00 2001
From: Jack Fletcher <jackowenfletcher@gmail.com>
Date: Mon, 7 Jun 2021 00:45:06 +0100
Subject: [PATCH] Add supported_methods() to CompressionMethod enum

---
 src/compression.rs  | 21 +++++++++++++++++++++
 tests/end_to_end.rs | 23 +++--------------------
 2 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/src/compression.rs b/src/compression.rs
index e0cc7d41..b8ecb264 100644
--- a/src/compression.rs
+++ b/src/compression.rs
@@ -121,6 +121,27 @@ impl CompressionMethod {
             CompressionMethod::Unsupported(v) => v,
         }
     }
+
+    pub fn supported_methods() -> &'static [CompressionMethod] {
+        static METHODS: [CompressionMethod; 4] = [
+            CompressionMethod::Stored,
+            //
+            #[cfg(any(
+                feature = "deflate",
+                feature = "deflate-miniz",
+                feature = "deflate-zlib"
+            ))]
+            CompressionMethod::Deflated,
+            //
+            #[cfg(feature = "bzip2")]
+            CompressionMethod::Bzip2,
+            //
+            #[cfg(feature = "zstd")]
+            CompressionMethod::Zstd,
+        ];
+
+        &METHODS
+    }
 }
 
 impl fmt::Display for CompressionMethod {
diff --git a/tests/end_to_end.rs b/tests/end_to_end.rs
index 50911f6d..d0d6ea0b 100644
--- a/tests/end_to_end.rs
+++ b/tests/end_to_end.rs
@@ -10,7 +10,7 @@ use zip::CompressionMethod;
 // the extracted data will *always* be exactly the same as the original data.
 #[test]
 fn end_to_end() {
-    for method in SUPPORTED_METHODS.iter() {
+    for method in CompressionMethod::supported_methods().iter() {
         let file = &mut Cursor::new(Vec::new());
 
         write_to_zip(file, *method).expect("Couldn't write to test file");
@@ -23,7 +23,7 @@ fn end_to_end() {
 // contents back out, the extracted data will *always* be exactly the same as the original data.
 #[test]
 fn copy() {
-    for method in SUPPORTED_METHODS.iter() {
+    for method in CompressionMethod::supported_methods().iter() {
         let src_file = &mut Cursor::new(Vec::new());
         write_to_zip(src_file, *method).expect("Couldn't write to test file");
 
@@ -62,7 +62,7 @@ fn copy() {
 // both the prior data and the appended data will be exactly the same as their originals.
 #[test]
 fn append() {
-    for method in SUPPORTED_METHODS.iter() {
+    for method in CompressionMethod::supported_methods().iter() {
         let mut file = &mut Cursor::new(Vec::new());
         write_to_zip(file, *method).expect("Couldn't write to test file");
 
@@ -188,20 +188,3 @@ const EXTRA_DATA: &'static [u8] = b"Extra Data";
 const ENTRY_NAME: &str = "test/lorem_ipsum.txt";
 
 const COPY_ENTRY_NAME: &str = "test/lorem_ipsum_renamed.txt";
-
-const SUPPORTED_METHODS: &'static [CompressionMethod] = &[
-    CompressionMethod::Stored,
-    //
-    #[cfg(any(
-        feature = "deflate",
-        feature = "deflate-miniz",
-        feature = "deflate-zlib"
-    ))]
-    CompressionMethod::Deflated,
-    //
-    #[cfg(feature = "bzip2")]
-    CompressionMethod::Bzip2,
-    //
-    #[cfg(feature = "zstd")]
-    CompressionMethod::Zstd,
-];