![]() # 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: ```bash 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](https://docs.rs/bevy_docs_extension_demo/0.1.1/bevy_docs_extension_demo/struct.TestAllTraits.html)  ## Release Notes On docs.rs, Bevy now displays labels indicating which core traits a type implements:  If you want to add these to your own crate, check out [these instructions](https://github.com/bevyengine/bevy/blob/main/docs-rs#3rd-party-crates). --------- Co-authored-by: Joona Aalto <jondolf.dev@gmail.com> Co-authored-by: Carter Weinberg <weinbergcarter@gmail.com> |
||
---|---|---|
.. | ||
README.md | ||
trait-tags.html |
Docs.rs Extensions
This directory includes some templates and styling to extend and modify rustdoc's output
for Bevy's documentation on docs.rs. Currently this consists of tags indicating core
bevy_ecs
traits.
3rd Party Crates
To use in your own crate, first copy this folder into your project, then add the following to your Cargo.toml:
[package.metadata.docs.rs]
rustc-args = ["--cfg", "docsrs_dep"]
rustdoc-args = [
"--cfg", "docsrs_dep",
"--html-after-content", "docs-rs/trait-tags.html",
]
[lints.rust]
unexpected_cfgs = { check-cfg = ['cfg(docsrs_dep)'] }
Local Testing
Build the documentation with the extension enabled like this:
RUSTDOCFLAGS="--html-after-content docs-rs/trait-tags.html --cfg docsrs_dep" RUSTFLAGS="--cfg docsrs_dep" cargo doc --no-deps --package <package_name>