Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include feature gated docs #54

Open
michaelkirk opened this issue Sep 28, 2020 · 0 comments
Open

Include feature gated docs #54

michaelkirk opened this issue Sep 28, 2020 · 0 comments

Comments

@michaelkirk
Copy link

michaelkirk commented Sep 28, 2020

Some of my docs are behind feature flags, e.g.

//!  In general, you can use the library like this
//! ```rust
//! use my_lib::foo;
//! assert!(foo())
//! ```
#![cfg_attr(
    feature = "serde",
    doc = r##"
## integration with `serde`

if you've enabled the optional `serde` feature, you can use the lib in fancy new ways!

\```rust
use my_lib::foo_method_that_requires_serde;

assert!(foo_method_that_requires_serde());
\```
"##
)]

However these aren't recognized as doc comments by cargo-readme.

rustdoc uses cfg/feature gated comments to produce UI like this, which I think is nice:
image

But perhaps less subjectively, doctests that require a feature will fail if that feature isn't enabled.

A brief dive into cargo-readme shows that this might be non-trivial. It looks like currently cargo-readme has implemented it's own parsing for comment extraction. I have no idea if it's possible, but maybe cargo-readme could actually use librustdoc to extract and parse comments?

Or, if you're feeling really evil you could generate the docs with rustdoc and parse the html back into markdown 😈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant