etemesi254 / zune-image

A fast and memory efficient image library in Rust
Other
332 stars 30 forks source link

image: only pull dependencies if the specific feature is activated #225

Closed Gui-Yom closed 2 months ago

Gui-Yom commented 2 months ago

Currently, if a user wants to only use the png format with simd, activating the simd feature will pull zune-jpeg too because the dependent feature isn't optional.

This change that by adding a ? which means the feature will only be activated if zune-jpeg was pulled in the first place.

An excerpt from the cargo docs :

The "package-name/feature-name" syntax will also enable package-name if it is an optional dependency. Often this is not what you want. You can add a ? as in "package-name?/feature-name" which will only enable the given feature if something else enables the optional dependency.

Note: The ? syntax is only available starting with Rust 1.60.

For example, let’s say we have added some serialization support to our library, and it requires enabling a corresponding feature in some optional dependencies. That can be done like this:

[dependencies] serde = { version = "1.0.133", optional = true } rgb = { version = "0.8.25", optional = true }

[features] serde = ["dep:serde", "rgb?/serde"]

In this example, enabling the serde feature will enable the serde dependency. It will also enable the serde feature for the rgb dependency, but only if something else has enabled the rgb dependency.

I did the same thing for the threads feature.

etemesi254 commented 2 months ago

Thank you, I wasn't aware of this