zip-rs / zip-old

Zip implementation in Rust
MIT License
731 stars 204 forks source link

use cfg-if and cfg_attr() to improve readability of feature guards #394

Closed cosmicexplorer closed 5 months ago

cosmicexplorer commented 1 year ago
  1. The cfg-if crate makes it easier to read conditional compilation logic.
  2. There is an undocumented hack used by many crates to get docs.rs builds to show whether some value is only available with a given feature enabled (see e.g. rust-random/rand#986).
    • The result can be tested with RUSTDOCFLAGS='--cfg docsrs' cargo doc (try opening e.g. CompressionMethod to see how this shows which enum cases are supported by which features).

This is not a breaking change, as cfg-if should generate the same code as before.

Pr0methean commented 5 months ago

The cfg-if crate was made redundant by the cfg! macro, which makes it possible to check configuration flags in a normal if statement. Even if that weren't the case, it doesn't look to me like this PR adds any readability -- the cfg-if! is just another pair of curlies to keep track of, and the cfg! macros remain just as complicated.

This repo is unmaintained. If you'd still like to submit an improvement, do so at https://github.com/zip-rs/zip2.