2

Most bigger crates have quite a few features enabled by default. Why should I use default-features = false in my Cargo.toml and only enable the ones that I actually need?

For example, if I use the chrono crate only to use DateTime<Local> I only need the clock feature to successfully compile my code.

The advantages I see is that there are less transitive dependencies that I don't use and thus shorten compilation times on a clean build. There are also less dependencies to worry about when upgrading.

So should this be the default way to use default-features = false on binary and library crates?

3
  • This increases the cognitive burden when adding dependencies, but also helps compile-time, sometimes a lot. Sensible? Definitely yes. Commented Aug 24 at 10:56
  • @Chayim Friedman You could also just add a crate regularly, implement what you need in your code and then add default-features = false. Most of the time the compiler will then tell you what features you need to enable. Commented Aug 24 at 11:26
  • It is certainly better hygiene for library crates that are publicly available to only depend on the minimal feature-set so as to not force downstream crates to build them needlessly if they want to opt out. Commented Aug 24 at 14:17

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.