sagebind / stability

Rust API stability attributes for the rest of us.
MIT License
28 stars 6 forks source link

The `unstable` feature badge for items #4

Closed loyd closed 2 years ago

loyd commented 2 years ago

It would be nice to add a badge unstable for items with #[stability::unstable]: 2022-01-15_11-19-05

A common approach for this (e.g. used by tokio) is relying on the doc_cfg feature. Details. It works fine with the current docsrs.

So, #[stability::unstable] can additionally generate #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]. However, it still requires #![cfg_attr(docsrs, feature(doc_cfg))] at crate level and

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

in Cargo.toml

The good news is that it doesn't fail even if these steps haven't added.

Will you accept the PR with an additional feature (docsrs-cfg?) that enables generation of #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]?

sagebind commented 2 years ago

I'm not sure adding the additional feature is worth the complexity, especially since you can use the doc_auto_cfg nightly feature to have doc(cfg) applied everywhere there is a cfg gated item. I use this in some of my crates to get the cfg badges:

#![cfg_attr(feature = "nightly", feature(doc_cfg))]
#![cfg_attr(feature = "nightly", feature(doc_auto_cfg))]

Then I enable the nightly feature in Cargo.toml like so:

[package.metadata.docs.rs]
features = ["nightly"]

There's probably other ways of doing this as well without needing to modify the stability macros.

loyd commented 2 years ago

doc_auto_cfg is much better than modifying stability. Thanks a lot)