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 tags on docs.rs #17758

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

Conversation

SpecificProtagonist
Copy link
Contributor

@SpecificProtagonist SpecificProtagonist commented Feb 9, 2025

Objective

Bevy's ECS provides several core traits such as Component, SystemParam, etc that determine where a type can be used. When reading the docs, this currently requires scrolling down to and scanning the "Trait Implementations" section. Make these core traits more visible.

Solution

Add a color-coded labels below the type heading denoting the following types:

  • Component
    • immutable components are labeled as such
  • Resource
  • Asset
  • Event
  • Plugin & PluginGroup
  • ScheduleLabel & SystemSet
  • SystemParam

As docs.rs does not provide an option for post-processing the html, these are added via JS with traits implementations being detected by scanning the DOM. Rustdoc's html output is unstable, which could potentially lead to this detection (or the adding of the labels) to break, however it only needs to work when a new release is deployed and falls back to the status quo of not displaying these labels.

Idea by JMS55, implementation by Jondolf (see https://github.com/Jondolf/bevy_docs_extension_demo/).

Testing

Run this in Bevy's root folder:

 RUSTDOCFLAGS="--html-after-content docs-rs/trait-tags.html --cfg docsrs_dep" RUSTFLAGS="--cfg docsrs_dep" cargo doc --no-deps -p <some_bevy_package>

Showcase

Check it out on docs.rs

trait tags

@SpecificProtagonist SpecificProtagonist added C-Docs An addition or correction to our documentation S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Feb 9, 2025
@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events M-Needs-Release-Note Work that should be called out in the blog due to impact labels Feb 9, 2025
@alice-i-cecile
Copy link
Member

I love the end result. I'll let others chime in on the impl though.

@alice-i-cecile alice-i-cecile added this to the 0.16 milestone Feb 9, 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 M-Needs-Release-Note Work that should be called out in the blog due to impact S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants