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

Include a list of struct methods in reference sidebar on struct pages #41123

Closed
mqudsi opened this issue Apr 6, 2017 · 9 comments
Closed

Include a list of struct methods in reference sidebar on struct pages #41123

mqudsi opened this issue Apr 6, 2017 · 9 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@mqudsi
Copy link
Contributor

mqudsi commented Apr 6, 2017

This is a suggestion for the formatting of reference pages for structs in rustdoc, in particular, to discuss the addition of a linked table of impl to the sidebar which would serve as

a) a quick way to identify methods a struct exposes which can be a great way to quickly find a function you know should exist but don't know the name of in rust, and
b) an easy way to navigate overly-long reference pages (currently, several parts of the rust book and documentation recommend "using ctrl+f to find the impl for xxxx"

As a concrete example, my suggestion would be for the string reference page to change like this:

unsorted methods

There are of course several questions about the layout and formatting of such a table. Should arguments be included? If yes, they add not-inconsiderable visual clutter, if no, what about overloads? Are they presented in alphabetical order or in the order they appear in the document? Do we include functions from trait implementations? Do we put them in a separate list?

Thanks for considering.

@est31
Copy link
Member

est31 commented Apr 6, 2017

I think the info is too complex to display in the sidebar, and already now you can click the - icon to get an overview.

@QuietMisdreavus
Copy link
Member

cc @rust-lang/docs

So, back in the halcyon days of December, I tried writing a table of contents like this. I didn't go to the point of writing out every single item, though; I just stopped at the headers. If this were accepted, I could just resurrect that branch.

rustdoc toc struct 1
rustdoc toc struct 2
rustdoc toc trait

@mqudsi
Copy link
Contributor Author

mqudsi commented Apr 6, 2017

Just for reference, (and perhaps as a counter to the "too much to list" argument) other projects include functions in the sidebar as an expandable list. Here's Microsoft's documentation for the string class for comparison:

image

And here's a screenshot with the functions list expanded, showing how they deal with overloads:
image

@est31
Copy link
Member

est31 commented Apr 6, 2017

@mqudsi just because they are bad you shouldn't imitate them. Also, C# has a much simpler type system and not all this bounds/trait stuff that we have.

@mqudsi
Copy link
Contributor Author

mqudsi commented Apr 6, 2017

@est31 that's a little harsh, isn't it? C# developers seem happy with their ecosystem, and MSFT's documentation structure and layout has changed many times over the years... a more natural conclusion would be that they found this to work (for them, at least).

@est31
Copy link
Member

est31 commented Apr 6, 2017

@mqudsi I'm happy with what's present with rustdoc today, and I don't want us to regress.

@QuietMisdreavus
Copy link
Member

On the other hand, for several types in std, there's so many methods that having to navigate them all is fairly imposing. And the [-] trick is fairly unknown, too. I think having some kind of table-of-contents would be helpful, even if it's just the high-level links I started adding.

And for reference, several of .NET's core types have just as many items - methods, fields, etc - on them as several of Rust's, if not more. The expanding sidebar table of contents is how they chose to introduce discoverability into their documentation. One could say the in-doc search is how rustdoc introduces that, but that's more of a means to find something you already know. It's hard to browse through the search bar.

@QuietMisdreavus
Copy link
Member

I've finished up that code work and made a PR in #41280.

frewsxcv added a commit to frewsxcv/rust that referenced this issue Apr 17, 2017
…laumeGomez

rustdoc: add a list of headings to the sidebar

It's another misdreavus rustdoc PR, which means it's time for Bikeshed City once again! `:3`

In an effort to aid navigation in long documentation pages, this PR adds a listing of headings to the sidebars of pages where such headings exist. For example, for structs, links to their fields, inherent methods, and trait implementations are available where applicable.

Examples:

* Modules/Crate roots
  ![image](https://cloud.githubusercontent.com/assets/5217170/25019930/1000fa3a-2052-11e7-98ff-ddf5af18b3e6.png)
* Enums
  ![image](https://cloud.githubusercontent.com/assets/5217170/25019954/33497f9e-2052-11e7-88cf-df46f1b3b8a3.png)
* Primitives
  ![image](https://cloud.githubusercontent.com/assets/5217170/25019978/4820bbc6-2052-11e7-8b5a-96a864eb2a5b.png)
* Traits
  ![image](https://cloud.githubusercontent.com/assets/5217170/25020093/bd1bc9f2-2052-11e7-9cd1-00a0ad8007bc.png)
* Structs
  ![image](https://cloud.githubusercontent.com/assets/5217170/25020145/d75206b0-2052-11e7-88cc-9e9525084775.png)

Open questions:

* Right now, these kinds of pages (and also unions) are the only pages that will receive the name header - pages for functions, constants, macros, etc, won't have the corresponding name in their sidebar. Should I print the name regardless and only add table-of-contents links for pages that have them? This would make them match, for example, a struct with no public fields, no methods, and no trait implementations. The latter would still have a "Struct MyStruct" line above the module contents, with no header links to speak of, whereas a function wouldn't even have "Function my\_function".
* This is only a header listing, but there has been requests to include a more-complete listing of fields/methods/traits/etc, for example in rust-lang#41123.
@Mark-Simulacrum Mark-Simulacrum added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jun 20, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 27, 2017
@steveklabnik
Copy link
Member

This has been fixed!
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants