Generate docs both with or without a feature

⚓ Rust    📅 2026-01-19    👤 surdeus    👁️ 4      

surdeus

Is it able to generate docs to include both foo_a and foo_b with cargo doc?

#[cfg(feature = "foo")]
pub fn foo_a() {}

#[cfg(not(feature = "foo"))]
pub fn foo_b() {}

I understand that in the most idiomatic Rust style, "features" are meant to be additive, adding a feature shall not remove a functionality. However, in my real case, this really happens: In my crate, an algorithm can be speedup with a cache. Using that cache needs users to implement additional traits, while on the contrary, certain functionalities are not provided with the cache since it is too hard to implement. So I need my doc to include both the additional trait with cache feature and functionalities without cache feature. Is it possible? Or is there another way to control the functionalities? (I don't think runtime panicking in functionalities with cache enabled is a great solution).

3 posts - 3 participants

Read full topic

🏷️ Rust_feed