How to document feature-gated derived traits?

100 Views Asked by At

I understand that I can use the cfg_attr attribute to conditionally derive Trait implementations for types. For example, A struct MyStruct which always implements Clone, Copy, and Debug, but which implements PartialEq if and only if the my-feature feature is enabled, can be defined as follows:

#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "my-feature", derive(PartialEq)]
struct MyStruct;

But is it possible to make the generated documentation reflect this? I would like the rustdoc-generated documentation to state that PartialEq is implemented for MyStruct if and only if the my-feature feature is enabled.

So far, I have only accomplished two outcomes, neither of which I want:

  1. If I compile the docs with the my-feature feature enabled, the generated documentation just says that MyStruct implements PartialEq, with no mention of feature gating
  2. If I compile the docs without the my-feautre feature enabled, generated documentation does not indicate that PartialEq is or can be implemented for MyStruct.
0

There are 0 best solutions below