Skip to content

Commit 1248cfd

Browse files
Update posts/2022-04-07-Rust-1.60.0.md
Co-authored-by: Eric Huss <[email protected]>
1 parent 15933cf commit 1248cfd

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

posts/2022-04-07-Rust-1.60.0.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ jpeg-decoder = { version = "0.1.20", default-features = false, optional = true }
8686
parallel = ["jpeg-decoder/rayon"]
8787
```
8888

89-
The `"package-name/feature-name"` syntax will also enable package-name if it is an optional dependency. Often this is not what you want, and starting in 1.60, you can add a ? as in `"package-name?/feature-name"` which will only enable the given feature if something else enables the optional dependency.
89+
There are two things to note in this example. First, the optional dependency `jpeg-decoder` implicitly defines a feature of the same name, which provides a means to enable the dependency. Second, the `"jpeg-decoder/rayon"` syntax enables the `rayon` feature of the `jpeg-decoder` dependency, *and* also enables the `jpeg-decoder` dependency.
90+
91+
Namespaced features tackles the first issue that optional dependencies are implicitly exposed as part of a package's public interface. You can now use the `dep:` prefix in the `[features]` table to explicitly refer to an optional dependency. This gives you more control to define the feature corresponding to the optional dependency, and to hide optional dependencies behind more descriptive feature names.
92+
93+
Weak dependency features tackles the second issue where the `"package-name/feature-name"` syntax would enable `package-name` if it is an optional dependency. Often this is not what you want, and starting in 1.60, you can add a ? as in `"package-name?/feature-name"` which will only enable the given feature if something else enables the optional dependency.
9094

9195
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:
9296

0 commit comments

Comments
 (0)