The additive nature of the flags is an important difference between the Rust flags and the Gentoo flags:
Quoting the Rust Cargo flags section about Flag unification:
A consequence of this is that features should be additive. That is, enabling a feature should not disable functionality, and it should usually be safe to enable any combination of features. A feature should not introduce a SemVer-incompatible change.
For example, if you want to optionally support no_std
environments, do not use a no_std
feature. Instead, use a std
feature that enables std
.
This is not checked anywhere automatically AFAIK; it is a convention, but if you want your library to be used as a Rust developer, you better hold to this convention because it’s the only way for your library to get traction in the Rust ecosystem.
Yes, they are really different: When a dependency is marked as optional in Rust/Cargo, a feature flag that shares its name is automatically made available, and this flag is automatically enabled once the optional dependency happens to exist during dependency resolution of the top-level package the library (directly or transitively) is used in. (see this section for details)
Thus, if you install both the Rust library uuid
and the Rust library serde
, you can now serialize/deserialize UUIDs because serde
is an optional dependency of uuid
. And if you also depend on arbitrary
you can now generate arbitrary UUIDs in property-based tests, because arbitrary
is also an optional dependency of uuid
.
But when you just depend on uuid
, you’re not waiting for any of that extra machinery to be compiled.
Compared to Haskell, where someone can depend on uuid
but has to manually add uuid-aeson
to support serialization* . And if you want to generate UUIDs for property testing, you need to add the quickcheck-instances
library. Good luck finding that if you don’t know where to look beforehand!
*I guess that for this particular example, desire for UUID support was so large that at some point it was built into Aeson itself, meaning that also anyone not using UUIDs pays for the UUID (specifically: uuid-types
) library to be compiled, but I digress. Feel free to replace uuid
with any other prevalent datastructure library, or replace aeson
with any other prevalent serialization, prettyprinting, hashing, generation, etc library.