Rust i̶n̶e̲x̲trospection

Is there some way to enumerate all public items in a crate, with canonical names and all types resolved?
The result of any calculation based on that enumeration does not have to be included in the crate itself.

Rustdoc has this information, but I don’t know whether it can generate an index in json or similar serialization. Or is there a compiler debug flag to dump data after some stage that could produce this?

My motivation is mainly generating bindings, which can be done as a wrapper. cbindgen already has this problem, and it is relatively simple, only looking for extern "C" functions and #[repr(C)] types with restricted content, so guessing what the names really mean works well enough. I am thinking about processing a more naturally written interfaces, for which having resolved types, and knowing about impls, would be important.

1 Like

I would love to have such a dump for diffing the API between crate releases. There’s semverver along these lines, but I’d like to have the data available to compare it myself.


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