Skip to content

Tracking Issue for doc_label_trait #156865

@ThierryBerger

Description

@ThierryBerger

Feature gate: #![feature(doc_label_trait)]

This is a tracking issue for allowing users to mark arbitrary traits to be displayed more prominently in rustdoc.

Image Image

Prototype: https://docs.rs/bevy_docs_extension_demo.

Public API

pub struct Magic;

#[doc(label_trait)]
#[doc(label_trait_color="#ff0000")]
pub trait ImportantTrait {}

impl ImportantTrait for Magic {}

Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

  • Add #[doc(label_trait)]: Display the labeled badge on a struct's dedicated page in rustdoc
  • Add #[doc(label_trait_color="#ff0000")]
  • Add a smaller colored badge next to items where relevant.
  • Final comment period (FCP)1
  • Stabilization PR

More context

From https://thierryberger.com/blog/rustdoc-notable-trait/.

offline copy in case above link goes dead.

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

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.

Additional context

Maintenance of the JS approach

Abandoned ideas

Unresolved Questions

  • Which API exactly should be implemented ? Maybe the doc(label_trait_color = "#ff0000") is enough to infer its existence.
    • doc(label_trait(color="#ff0000"))]
  • How should the color be written (hex...?)
    • Hex 👌
  • Should rust-analyzer hop on that feature to also display those traits? (notable_traits display them on hover of an type implementing that trait)
  • Shouldn't we reuse notable_trait?
    • Reading notable_trait feature really makes it feel similar: Rustdoc keeps a list of a few traits that are believed to be "fundamental" to types that implement them.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-rustdoc-uiArea: Rustdoc UI (generated HTML)C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-unimplementedStatus: The feature has not been implemented.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.T-rustdoc-frontendRelevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions