Looking to Capture Type Documentation


I'm Yoshiki, a PhD student at CMU.

I was wondering if there was a way to easily get type information from rust's documentation.

For example, I want to enumerate all functions of std::string::String, and get the type signatures for them.

I noticed search-by-type was implemented in PR#23289, but it looks like the search-index.js currently being used is different from the one implemented in the PR (probably performance reasons).

Any help with the JSON format, or suggestions on alternative methods will be greatly appreciated.

Thank you for your time.

might be helpful too, if you want to script the queries.

1 Like

Hey Yoshiki! Welcome! I graduated from Pitt :slight_smile:

Is the requirement to get it from the documentation, or to get it from source code? From

I will guess that it's not a hard requirement that comes from the docs. :slight_smile:

There are a few options. None of them are fantastic, to be honest.

The first option is to look at save-analysis data. This is produced by the compiler when you pass a special flag, and is how the RLS works. To generate this, you'd do RUSTFLAGS="-Z save-analysis" cargo check. This produces some JSON files that you could look at. This is all extremely unstable.

Another option is rustdoc and JSON. rustdoc used to support a JSON output; it was not really used by anyone, and was broken for a long time, so we removed it rather than fix it. I am sure if you wanted to bring it back, there would be support from the team.

The best option, in my opinion, isn't quite ready for prime time yet, but may be good enough for you so far. And that would be to use rust-analyzer as a library. I have not attempted to use this yet, so I can't give you great help, but if I were to tackle this problem today, this is where I'd start.

I hope that helps!


Hi Steve.

Thank you so much for providing such an extensive answer.

Sorry I got swamped with work for several days.

I tried RUSTFLAGS="-Z save-analysis" with the rust standard library compile, and got multiple large JSON files. It looks like the old RLS interface might parse the JSON for me, so I'll try it out over the weekend.

On the other hand, I also took a look at rust-analyzer. It seems a little bit more complex than the old RLS with analysis state and incremental/lazy updating. Although, I assume the complexity is worth it when considering real-time user experience.

I'll see which fits my situation better.

Again, thank you very much for your help. :grin:

P.S. It's very warm in Pittsburgh this year. I got lucky on my first East Coast winter.

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