Optional nightly features in published crates

I have a crate that I feel would do well to have an opt-in for some nightly features.

I added a feature to enable the nightly features, but I quickly realized that this breaks stable builds when one passes --all-features.

I'm considering adding a --cfg option to enable the nightly features instead, to keep --all-features stable-compaible.

Is there any ecosystem consensus on how to handle these types of things?

I would say that:

  • In general, enabling some feature may impose some requirement on the build or execution environment (e.g. presence of system libraries, additional build tools).
  • Requiring nightly is an example of such a requirement.
  • So, it is "not surprising" that --all-features might fail for any package; designing your package so that it succeeds that way is a convenience for your development work, not a requirement for your package to be well-behaved.

Hmm.. I'm a little annoyed that I'm finding your argument persuasive. Basically, typing cargo test --all-features is something I do so often that it is more of a muscle memory thing, and I was hoping to avoid untraining it.

I'll switch back to using features and see how it goes.