How Does Tokio Get the Cool 'Supported on feature="something" only' in

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

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?


#[doc(cfg(feature = "process"))]:


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 features:

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, but I didn't find anything.

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

1 Like

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.