Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trait-based sections on docs.rs #17821

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

SpecificProtagonist
Copy link
Contributor

@SpecificProtagonist SpecificProtagonist commented Feb 12, 2025

Objective

Trait tags for core Bevy traits are shown on the doc page of individual items (#17758). However, they are not visible at a glance in listings, instead the individual pages must be visited.

Solution

Add individual listings for the core Bevy traits. Types in the module that implement them get moved there. If a type impls multiple of these traits, it appears in all relevant listings.

Unfortunately, fetching the linked items in JS to check which traits they implement, as is done for the pages of individual types, leads to a visible delay. Therefore the data about which tags each item has needs to be embedded in the page; this is done via a new tool that adds an invisible div to the module doc comment. This modification of the source code is only intended for generating the rustdoc output and should not be committed to main.

I haven't adjusted the publishing process yet – François turned off dirty repo state during publishes just three days ago :P
We could either allow it again or publish with a separate git tag like "v0.16.0-docs".

Blocked on #17857

As a followup PR it should be made easier for interested 3rd-party bevy crates to use this.

Alternatives

Keep items in existing sections but add trait tags in the form of icons (currently in the form of a single letter) in front of item names in listings, matching the colors of the existing tags (and with a hover text naming the trait). Using icons both provides an redundant information channel for accessibility and is compact.

Screenshot from 2025-02-12 20-28-12

This is implemented in commit 2d1f0d0 if you want to try it out.

Testing

Run the following:

cargo run -p embed-trait-info-in-source
RUSTDOCFLAGS="--html-after-content docs-rs/trait-tags.html --cfg docsrs" RUSTFLAGS="--cfg docsrs_dep" cargo doc --no-deps --workspace

Showcase

Screenshot from 2025-02-13 14-56-10

More examples

Screenshot from 2025-02-13 15-13-43

@SpecificProtagonist SpecificProtagonist added C-Docs An addition or correction to our documentation A-ECS Entities, components, systems, and events S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Feb 12, 2025
@SpecificProtagonist SpecificProtagonist changed the title Trait tags in listings Trait tags in listings on docs.rs Feb 12, 2025
@alice-i-cecile alice-i-cecile added the X-Contentious There are nontrivial implications that should be thought through label Feb 12, 2025
@alice-i-cecile
Copy link
Member

I love the concept, but as @JMS55 says, the icon set isn't quite doing it for me. They're neither clear nor particularly pretty. Could we use single colored letters maybe?

@alice-i-cecile alice-i-cecile added this to the 0.16 milestone Feb 12, 2025
@kristoff3r
Copy link
Contributor

I really like the listings per core type, this is something I've wanted for ages!

The implementation having to change the source while building is unfortunate though. Allowing that makes it easier to do sneaky supply chain attacks, and some sandboxed build systems like Nix and Bazel mount the source directories as read-only. It would be better if the data can be added to the generated docs after they've been built instead.

@SpecificProtagonist
Copy link
Contributor Author

SpecificProtagonist commented Feb 13, 2025

The implementation having to change the source while building is unfortunate though.

Yup. I'd say a path forward would be to propose a change to docs.rs to allow postprocessing the html output.
In the mean time, we could either:

  • publish the modified source, or
  • add a build script or similar that is only active on docs.rs & dev-docs.bevyengine.org

@SpecificProtagonist
Copy link
Contributor Author

I think I've found the solution:

  • replace the JS implementation with a tool that calls rustdoc and then modifies the generated HTML
  • set package.metadata.docs.rs.cargo-args to --config build.rustdoc=<path to the tool>

@SpecificProtagonist SpecificProtagonist added S-Blocked This cannot move forward until something else changes and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Feb 14, 2025
@SpecificProtagonist SpecificProtagonist changed the title Trait tags in listings on docs.rs Trait-based sections on docs.rs Feb 14, 2025
@alice-i-cecile alice-i-cecile added X-Controversial There is active debate or serious implications around merging this PR and removed X-Contentious There are nontrivial implications that should be thought through labels Feb 24, 2025
@alice-i-cecile alice-i-cecile removed this from the 0.16 milestone Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Docs An addition or correction to our documentation S-Blocked This cannot move forward until something else changes X-Controversial There is active debate or serious implications around merging this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants