How Does Tokio Get the Cool 'Supported on feature="something" only' in Docs.rs?

How does tokio get the cool 'Supported on feature="something" only' annotation in Docs.rs?

I thought this was really useful. Is there a way for me to add this kind of annotation to a specific function in a crate?

image

#[doc(cfg(feature = "process"))]: https://github.com/rust-lang/rust/issues/43781

2 Likes

It's a nightly only feature.

1 Like

Cool thanks! :slight_smile:

Is there a way to put it in a crate such that it only enables it on Nightly and then just ignores it on stable?

When I put the #![feature(doc_cfg)] in the crate it will not compile on stable ( which makes sense ). Can I make it conditional?

You can use #[cfg_attr(condition, attr)] to set them conditionally, and you can set docs.rs-only features: https://docs.rs/about/metadata

1 Like

If you search for docsrs in the Tokio codebase, both the rs source and Cargo.toml, you will see how Tokio did it.

1 Like

Thanks, I found it now. Initially I was confused because I was looking for annotations on the functions in the source on docs.rs, but I didn't find anything.

It's inside the cfg_* macros that Tokio use.

1 Like