Add SUPPORTED_METHODS constant

This commit is contained in:
Jack Fletcher 2022-01-24 20:05:54 +00:00
parent 772ab59471
commit 31c5fe8169
2 changed files with 19 additions and 41 deletions

View file

@ -121,27 +121,6 @@ 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 {
@ -151,9 +130,24 @@ impl fmt::Display for CompressionMethod {
}
}
/// The compression methods which have been implemented.
pub const SUPPORTED_METHODS: &[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,
];
#[cfg(test)]
mod test {
use super::CompressionMethod;
use super::{CompressionMethod, SUPPORTED_METHODS};
#[test]
fn from_eq_to() {
@ -166,22 +160,6 @@ mod test {
}
}
fn methods() -> Vec<CompressionMethod> {
vec![
CompressionMethod::Stored,
#[cfg(any(
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib"
))]
CompressionMethod::Deflated,
#[cfg(feature = "bzip2")]
CompressionMethod::Bzip2,
#[cfg(feature = "zstd")]
CompressionMethod::Zstd,
]
}
#[test]
fn to_eq_from() {
fn check_match(method: CompressionMethod) {
@ -194,7 +172,7 @@ mod test {
assert_eq!(to, back);
}
for method in methods() {
for &method in SUPPORTED_METHODS {
check_match(method);
}
}
@ -207,7 +185,7 @@ mod test {
assert_eq!(debug_str, display_str);
}
for method in methods() {
for &method in SUPPORTED_METHODS {
check_match(method);
}
}

View file

@ -5,7 +5,7 @@
#![warn(missing_docs)]
pub use crate::compression::CompressionMethod;
pub use crate::compression::{CompressionMethod, SUPPORTED_METHODS};
pub use crate::read::ZipArchive;
pub use crate::types::DateTime;
pub use crate::write::ZipWriter;