Skip to content

Commit

Permalink
refactor: Eliminate deprecation warning when --all-features implici…
Browse files Browse the repository at this point in the history
…tly enables the deprecated feature
  • Loading branch information
Pr0methean committed May 16, 2024
1 parent fbf111e commit 1cb0e1b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ tempdir = "0.3.7"
aes-crypto = ["aes", "constant_time_eq", "hmac", "pbkdf2", "sha1", "rand", "zeroize"]
chrono = ["chrono/default"]
_deflate-any = []
_all-features = [] # Detect when --all-features is used
deflate = ["flate2/rust_backend", "_deflate-any"]

# DEPRECATED: previously enabled `flate2/miniz_oxide` which is equivalent to `flate2/rust_backend`
Expand Down
18 changes: 9 additions & 9 deletions examples/write_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ struct Args {
enum CompressionMethod {
Stored,
Deflated,
DeflatedMiniz,
DeflatedZlib,
DeflatedZlibNg,
Bzip2,
Zstd,
}
Expand All @@ -50,22 +50,22 @@ fn real_main() -> i32 {
#[cfg(feature = "deflate")]
zip::CompressionMethod::Deflated
}
CompressionMethod::DeflatedMiniz => {
#[cfg(not(feature = "deflate-miniz"))]
CompressionMethod::DeflatedZlib => {
#[cfg(not(feature = "deflate-zlib"))]
{
println!("The `deflate-miniz` feature is not enabled");
println!("The `deflate-zlib` feature is not enabled");
return 1;
}
#[cfg(feature = "deflate-miniz")]
#[cfg(feature = "deflate-zlib")]
zip::CompressionMethod::Deflated
}
CompressionMethod::DeflatedZlib => {
#[cfg(not(feature = "deflate-zlib"))]
CompressionMethod::DeflatedZlibNg => {
#[cfg(not(feature = "deflate-zlib-ng"))]
{
println!("The `deflate-zlib` feature is not enabled");
println!("The `deflate-zlib-ng` feature is not enabled");
return 1;
}
#[cfg(feature = "deflate-zlib")]
#[cfg(feature = "deflate-zlib-ng")]
zip::CompressionMethod::Deflated
}
CompressionMethod::Bzip2 => {
Expand Down
3 changes: 2 additions & 1 deletion src/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::env::var;

fn main() {
if var("CARGO_FEATURE_DEFLATE_MINIZ").is_ok() {
if var("CARGO_FEATURE_DEFLATE_MINIZ").is_ok()
&& var("CARGO_FEATURE__ALL_FEATURES").is_err() {
println!("cargo:warning=Feature `deflate-miniz` is deprecated; replace it with `deflate`");
}
}

0 comments on commit 1cb0e1b

Please sign in to comment.