A library requiring stable or nightly

Hey there. I've got a library that I'd like to release to support two flavours of the toolchain: stable and nightly. When using stable, I'd like to use the async-trait library. When using nightly, I'd like to enable the async-trait functionality found in nightly. I'm thinking of having a default std feature that'd bring in the async-trait lib etc.

Are there examples of how best to go about this?

Cargo has no features for targeting nightly Rust, so every solution is a workaround.

  • You can release two different libraries, or
  • hide nightly functionality behind a feature flag (see cfg_attr) and instruct users to enable that flag manually,
  • or write build.rs script that checks rust version and sets a custom cfg.
2 Likes

Caution: this can result in a library which stops compiling when nightly changes (a feature is changed, or a feature flag is removed because the feature has been stabilized), even if the user of the library doesn't need the nightly-only functionality of the library but is compiling on nightly for other reasons.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.