Idea: explore rustdoc with a query language instead of as a website

I've been thinking it would be nice if I could explore my dependencies with some sort of query language like SQL instead of browsing through the website generated by rustdoc. I generally find it faster to type out a question than to click through links. Sometimes I also have specific questions that I'm not sure there's a way to answer from rustdoc websites. For example, "Given T, what types implement From<T>?" I don't have an example of what such a query would look like, because I'm not sure how this system would work and I don't know SQL yet, but hopefully you have an idea of what I'm talking about?

So my first question is, has anyone done something like this before? I think the answer is no because I can't find any information about something like this online. So my second question is how could we go about building a system like this? rustdoc has this -w json option (which can be used with cargo by doing something like RUSTDOCFLAGS='-wjson -Zunstable-options' cargo +nightly doc) which produces a sort of json schema of all the items in your crate (and in all of your dependencies when used with cargo). Then I imagine we would want to preprocess this json, maybe reorganizing it in the way that makes the most sense to the programmer, and maybe merging the output for different crates so you can query them all at once. Then we would want to give the programmer a way to query it. For example, we could translate the json schema into a sqlite database. Or maybe we could query the json directly. I don't really know what graphql is, but it looks like json, maybe we could use that?

Anyways, I'm just spitballing ideas here. Is anyone else interested in something like this? Does anyone with more experience with query languages than me have some thoughts on this?


Are you looking for something like Hoogle, but for Rust ? Where you can type in a Type expression with variables, and get a list of all functions / member functions that match ?

1 Like

Maybe something like that, I'm not sure how far the features of Hoogle extend.

Here's an example of what I'm talking about: today I was trying to figure out why my project depends on the chrono package. By using cargo tree -i chrono I was able to find the chain of crate dependencies, but that still didn't tell me where chrono is used in my code. So I decided to try and find structs in my project which have a member from the chrono crate. I don't think there's any good way to search for that with the rustdoc generated website, though. Here's what I think a SQL query for that might look like:

SELECT type.path,, struct.path,
FROM type, member, struct
WHERE = member.type_id
AND = member.parent_id
AND type.crate = 'chrono'

Here each row of the member table would represent an entry inside a struct or enum variant. Sorry, I've never written SQL before, I hope that makes sense.

This sounds like the kind of question that will be much better at answering than anything looking at rustdoc json?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.