Rustdoc: make notable traits useful

Posted 2026-05-23 15:33:19 ‐ 3 min read

Let's explore what Bevy has been doing to guide their users to the correct concepts, and how Rustdoc (or you?) can help.

Discoverability is not my best trait.

The need (blabla...)

Trait-heavy framework APIs (Bevy, but also Diesel, axum, embedded HALs) have poor discoverability in default rustdoc. From a type page it is hard to answer: is this a Component? a Resource?

Trait impls are listed flatly, far from the type's header, and conceptual grouping of items by trait role does not exist.

Bevy has been experimenting with augmenting rustdoc output to surface these concepts. Let's see what you think!

Our approach today

Controversial

  • To avoid clutter we filter them out depending on combinations (a Resource is also a Component, but a user isn't usually interested in knowing that it's a Component)
  • Trait sections: module pages group items by trait role instead of one flat list. See https://github.com/bevyengine/bevy/pull/17821.

How it's implemented

The current implementation is JavaScript shipped from the crate that mutates rustdoc's generated DOM at load time. It works, but:

  • It depends on rustdoc's HTML/CSS structure, which is not a stable interface.
  • Shipping JS from a crate to alter rustdoc output is... controversial, and will™️ be forbidden in the future.

What we ruled out

Rustdoc specifics

Rustdoc's "Notable traits" may be a good concept to hook onto to power this feature.

How?

I'll detail my understanding on how rustdoc works, but the following may be incorrect or not the correct approach, read it as a discussion starter.

Gotta have that data

If we choose to hook on to the notable trait API, we already have that info :tada: !

Gotta display that data

Rustdoc queries annotations (this should probably linked in the above issue) through attributes.

So I expect it to be straightforward to retrieve that information where we have the traits implemented by our type.

For other areas (list of types), there is get_filtered_impls_for_reference which may be helpful to start an implementation.

So, who's up to implement it?

Additional context

Maintenance of the JS approach

Abandoned ideas