I have code like the following:
#[cfg(feature = "alloc")]
extern crate alloc;
/// Something to do with [`Vec<u8>`].
///
/// [`Vec<u8>`]: alloc::vec::Vec
trait Foo {}
The Foo
trait exists unconditionally. However, when running cargo doc
without the alloc
feature, the intra-doc link to alloc::vec::Vec
is broken because the extern crate alloc
line is not compiled.
What is a good way to address this problem? A few details/things I've considered:
- This isn't a problem for docs.rs because my
Cargo.toml
file has the following:[package.metadata.docs.rs] all-features = true
- I considered making it so that, when docs are being built, all features are enabled, but this could cause problems in the future if I introduce mutually-exclusive features, and it also makes all of my
cfg
s more complex. - Maybe I should just not care and only make sure that intra-doc links aren't broken when all features are enabled?
Has anyone run into this before? Is there a standard solution in the community?