cargo-readme
cargo-readme copied to clipboard
Include feature gated docs
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:
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 😈