-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Group navigation items in the docs by source crate/module #105307
Comments
@rustbot label C-enhancement T-rustdoc A-rustdoc-ui |
I just tried to implement this feature and got it basically working, right now the rendered page looks like: There are two questions I'm not sure about:
|
Pondering: does this need the module information? Would crate headers be sufficient? |
What's the drawback of having module information? Group with modules can provide fine-grained categorization, but it does take more space in the side bar. The benefit is especially noticable for traits in std / core, because there are various traits for different purposes in them. |
Thanks for thinking about this problem @cmpute, and prototyping a solution! I think this is not the right solution, though. You mention that most types have few methods and many traits, but I think that's not universally true. Plenty of types (particularly in std) have many methods and few traits. And there are some traits that are extremely common, like You're right that for numeric types, the sidebar is incredibly noisy. This is particularly due to the nature of the mathematical traits, where each trait (e.g. Add) needs N implementations for the N numeric types it can interact with. Then multiply by another 2x since you need separate implementations for winding up on the left or right side of the Probably the What if we introduced a "Numeric Trait Implementations" section, in both the sidebar and the main document. It would handle all the traits from core::ops. For the sidebar, instead of listing
Rustdoc could also detect when the operations are not symmetrically defined, and say e.g. "IBig can be on the left hand side of an add operation with UBig". This would happen to solve another problem: In the std docs, the numeric primitive types are some of our largest pages, and the slowest to load. The massive number of implementations is not very informative to the reader. A summary would be much more informative. And while rustdoc tends to mimic the presentation of the source code, this is a place where it diverges: the numeric traits are almost never implemented by hand because it would be so tedious and error prone. Instead they are usually implemented by a macro. So there's no reason for the documentation to be so much more verbose than the source code. |
Or perhaps a more useful format to present the summary would be a table:
|
Thanks for your reply! I think it's a good idea to only document operator traits! But one concern come to mind is what about user defined "operator" traits? Such as num_traits::Pow, dashu_base::DivEuclid. Maybe it's better to create an attribute like For combining the docs in the main document, I'm guessing it's not a perfect solution to combine the trait docs. Maybe it's okay for core/std docs, but I'm hoping for a more generalizable solution for other traits (including user defined ones). And what if the user indeed has specialized documentation for the implementation (though in this situation maybe it's okay to just not combine them) I also want to mention another point I have when I proposed this change. One benefit of grouping the traits by module is that, the relevant traits are closer in the sidebar. For example, |
This is awesome! But how to support user defined traits is still a question |
The way I think of this is: rustdoc is a tool to help the doc author write docs. Sometimes it's much harder to make the tool write the docs than for the crate author to write them. So in this case, the crate author could write a section with a summary like the one I provided, listing all the types for which This has the downside that the doc author could make a mistake when hand-writing their summary. However, the author could improve on this by automating creation of the summary inside the macro they use to generate all the various trait implementations. |
I'm not aware of a way to automate generation of this kind of table in rust macro, do you mean using a proc-macro or something? How about using an attribute item as I proposed? By this way we can help the automate this process for everyone. |
So for instance with
You could rearrange things so these are all inside one big macro call:
That should allow the macro to have a high enough view to be able to generate a summary table. But I haven't tried it there may be obstacles I haven't foreseen.
It's best to avoid adding new features until we have exhausted the possibility of a solution that uses existing features. |
With that macro, the documentation will still be generated on a specific (or each) implementation, right? I guess this kind of work still has to be done in the rustdoc side. If a new feature is not desired, then I think the best way is to come up with a heuristic that automatically combine this kind of traits, for example here is one I quickly come up: we could combine the implementations if
|
Furthermore, I think it's better to focus on changing the behavior of the sidebar first. For the main documentation, the ultimate solution is to generate a good summary of all the items, and the summary of trait implementations can be combined into that. I would like to implement the generating a table of contents for the docs, but I'll need some time to come up with a good style and maybe I will first post a prototype as zulip. 😄 |
No, I believe it should be possible to generate one set of documentation per macro invocation. Note that there is something else missing from my sketch: you might also need to encompass the type definition in your macro invocation so that you can add the appropriate |
Well, that's true. But one point I heard a lot is that how rustdoc can help people write good documentation. If it's too bothersome, I guess most people (including me lol) will not bother to do this. Anyway, I think it can be mitigated by a great ToC and I'm more willing to put effort into that. |
A simple solution based on your suggestion is that we just collapse all the implementations of the same trait into folded-by-default lists (in the sidebar), either always or when some criteria are met. |
Btw just to toss an idea into the pile -- I made a prototype a while ago of a pop-out table of methods: (I even wrote a little paper about it: https://arxiv.org/pdf/2011.05600.pdf) Honestly I'm not a huge fan of the sidebar in the first place, since a linear column isn't a great way to organize a large amount of information. The prototype above was explicitly designed to use a large amount of screen space. |
@willcrichton That looks really nice! Do you happen to have the implementation opened? For the sidebar, although it's not as good as a full table in terms of information, it's still pretty useful for navigation across the page. So ideally we should have the both. |
Yep, it's sitting around in a branch on my Rust fork: willcrichton@d825c8a |
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 and rug::Integer).
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.Current behavior
(This documentation comes from
dashu-int::UBig
)Proposed behavior
The style for the module names is to be defined.
The text was updated successfully, but these errors were encountered: