Reputation: 5370
For the sake of making debugging easier and such, I would like to know all traits implemented for a type within a certain scope. Can I get rustc
to provide me this information? If so, how?
Upvotes: 8
Views: 1226
Reputation: 7030
Here's a janky method for getting this information during development, using autocomplete (I came here hoping for something a little more robust than autocomplete, but have not found it yet).
Using a JetBrains IDE with the rust plugin, within the desired scope, I can pull up an autocomplete list of fields/methods for any type by typing:
<NameOfType>::
The traits they implement will be listed alongside the methods when applicable:
So, you can scroll through that list and hopefully locate the traits you're looking for. Not great, but works in a pinch.
Upvotes: 1
Reputation: 29981
Use rustdoc
/cargo doc
.
rustdoc
creates a section with all trait implementations for a given type. For example with Vec
:
If you would like to do this for your own crate, you might find --document-private-items
to be useful. See also How to generate documentation for private items.
Upvotes: 1