-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
rustdoc: allow searching by trait bounds #84824
Comments
I definitely see the utility of this, but I wonder if it might not be better solved by the documentation itself. For instance, right now the documentation for
Instead it could say:
The advantage of this approach is that it can work across crate boundaries, even when the crates are not built together. Right now, crates on docs.rs aren't aware of each other when built. |
Yeah, what you said is good but in reality I have never seen any crates that have docs that do this. Documentation is good only if there are good documentation writers (rust have lots of good documentation but I see most low-level stuff documentation is bad), in any case we always have the trait bounds so giving the user the ability will always benefit the users compared to just documentation because we can't force how the documentation is written. |
Per rust-lang/rust#84824, it can be hard to figure out from the trait bounds what types meet those bounds.
Here's an idea: we could look to see what types are used to satisfy T in a crate's tests, doctests, and internal code. Then we could offer a hover tip on |
See rust-lang/rfcs#3123 for a more fleshed out idea around this. |
https://docs.rs/hyper/0.14.7/hyper/client/conn/struct.Builder.html
Some libraries have trait bounds more complicated and more that one items, some of it could be automatically-derived or some could be specifically implemented for a certain structs/enums. Other libraries such as diesel also make use of trait bounds extensively.
If the user wants to find out which type can they used within the trait bound. According to the context above that they want to find out what can they use for
T
, they had to click onAsyncRead
, capture all the implementations in mind and then go back and click onAsyncWrite
and see which types appear again since trait bound is additive, it needs to satisfy all the traits.If the user implemented a struct/enum that implemented all the specified trait bound then they know which is it, but if the user is using a third party library, chances are they will easily get lost or take some time to figure out what can
T
be without implementing it themselves. Without examples of the function, it would be require some time to go through and understand all the traits and their respective implementations.Maybe we could have a way for user to know what could possibly be the types that they can use for
T
without going through the whole codebase? Behaving like goto implementation of language server, except now it can show what types satisfies all the specified trait bounds?Of course the solution may not need to be perfect. I can think it may not work well with auto-traits since it could be hard to do that. Two solutions I can think of, we can have a
implementations
section within the search tab that shows all the types that satisfies the trait bounds specified, likeAsyncRead + AsyncWrite
(but not sure if we can also do it forUnpin
orSend
, maybe we couldn't cover lifetime at all). Another thing I can think of is that we can maybe provide some information when one clicks/hover onio
orT
then it will show the types that implement it, similar to the auto-traits section within the doc page.Not sure if it is feasible, just an idea. Maybe we even had to have another search index if we can't reuse the existing one and not sure if it's worth it, or maybe we could make it lazily loaded only when they reached the tab. One issue I see is that types being shown may not be able to show standard library types and that may be an issue.
The text was updated successfully, but these errors were encountered: