# Group navigation items in the docs by source crate/module

**URL:** <https://internals.rust-lang.org/t/group-navigation-items-in-the-docs-by-source-crate-module/17903>\
**Category:** tools and infrastructure\
**Created:** [December 3, 2022, 12:43am UTC](https://internals.rust-lang.org/t/group-navigation-items-in-the-docs-by-source-crate-module/17903 "2022-12-03T00:43:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmpute](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cmpute/32/9141_2.png) [@cmpute](https://internals.rust-lang.org/u/cmpute)\
**Post date:** [December 3, 2022, 12:43am UTC](https://internals.rust-lang.org/t/group-navigation-items-in-the-docs-by-source-crate-module/17903/1 "2022-12-03T00:43:35Z")

</div>

I would like to propose a feature request for the rustdoc. For the documentation generated for a type, it seems great to me if the trait implmentations can be grouped by the name of source crate (even source module) in the left navigation panel. Usually, a type won't have too many methods but it can have numerous trait implmentations (especially for numberic related types such as [BigUint](https://docs.rs/num-bigint/0.4.3/num_bigint/struct.BigUint.html) and [rug::Integer](https://docs.rs/rug/1.17.0/rug/struct.Integer.html)).

People usually don't browse the trait implementations by the alphabetic order, they do directly by searching. But sometimes if I don't know which trait I'm looking for, but just want to know what functionalities the type support, it will be great if I can find the implementations by the crate / module name. For example, the implementation of all the arithmetic traits (`Add`, `Sub`, etc) can be grouped by the `core::ops` module name.

I would like to create an issue for this if there's not an approach that I just haven't known yet.

---

<div class="post-metadata">

**Author:** ![cmpute](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cmpute/32/9141_2.png) [@cmpute](https://internals.rust-lang.org/u/cmpute)\
**Post date:** [December 7, 2022, 1:38am UTC](https://internals.rust-lang.org/t/group-navigation-items-in-the-docs-by-source-crate-module/17903/2 "2022-12-07T01:38:28Z")

</div>

FYI, I have created [an issue](https://github.com/rust-lang/rust/issues/105307) for this and have done some preliminary work. Here are two examples: [page1](http://zyxin.xyz/rustdoc-group-test/dashu_base/sign/enum.Sign.html), [page2](http://zyxin.xyz/rustdoc-group-test/dashu_int/struct.UBig.html).

There are three questions I'm not sure about, which are mentioned in the issue:

> 1. Should the module names be embedded in the title like the picture above, or they should be formatted as subtitles under the "Trait Implementation" section?
> 2. Is it useful to have some rules to simplify the groups to prevent generating too many groups (such as don't create a group if there is only one trait in that group)
> 3. Do we also group the traits in the sections for auto and blanket trait implementations?

Please give some comments on these choices if you are interested in this change 😊

---

<div class="post-metadata">

**Author:** ![djc](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/djc/32/1592_2.png) [@djc](https://internals.rust-lang.org/u/djc)\
**Post date:** [December 7, 2022, 1:51pm UTC](https://internals.rust-lang.org/t/group-navigation-items-in-the-docs-by-source-crate-module/17903/3 "2022-12-07T13:51:48Z")

</div>

In source code I usually try to order trait implementations in order of decreasing rarity: boring stuff like Default or Clone comes at the bottom, bespoke local traits near the top. Maybe it would be feasible to do use similar heuristics here? At least could do local traits, then foreign non-std traits, then std traits?

---

<div class="post-metadata">

**Author:** ![cmpute](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cmpute/32/9141_2.png) [@cmpute](https://internals.rust-lang.org/u/cmpute)\
**Post date:** [December 7, 2022, 3:36pm UTC](https://internals.rust-lang.org/t/group-navigation-items-in-the-docs-by-source-crate-module/17903/4 "2022-12-07T15:36:10Z")

</div>

That's a great suggestion! But I'm not sure if it's the same case for all users, because for me, std/core traits are often very useful and important as well. How about we put the local traits at the top (with name `crate::xxx`, and put other trait groups under them sorted alphabetically?

Second thought: I'm not sure how this heuristic will get along with the std library docs itself, displaying `crate::xxx` for std traits seems weird.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 7, 2023, 3:36pm UTC](https://internals.rust-lang.org/t/group-navigation-items-in-the-docs-by-source-crate-module/17903/5 "2023-03-07T15:36:59Z")

</div>

Closed on March 7, 2023, 3:36pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
