How to search for trait impls in crate docs?

I'm doing research for a blog post on the traits in Rust's standard library. In the blog post I'd like to point out notable implementation examples for each trait, both within the standard library and also from popular crates.

One thing I like about the standard library docs is that I can go to any trait and at the bottom of the trait docs I can see a complete list of every type that implements that trait.

I would like to have the same information for crates but if I search for PartialEq or Ord or whatever in the crate docs the search returns no results, even if there are types within the crate that I know implement those traits.

I don't want to manually search by hand, going from type to type, within a crate to maybe find a trait implementation I'm looking for. Is there any faster way to do it?

1 Like

I once managed to integrate a copy of the standard library docs into the cargo doc, without actually needing to copy the whole things, by means of symbolic linking, etc. using a small batch script on Windows. I can try to look that up later today for details; IIRC with the standard library docs in place, rustdoc was able to correctly add additional impl entries to pages like PartialEq or Ord. Of course the “brute-force” way of actually copying the entire standard library documentation into your crate documentation folder should work as well. IIRC, I based my experiments on this comment (or at least this discussion) on GitHub

If you want to have the impls added for one or multiple crates from crates.io, just add them all as dependencies.

Actually, for completeness, I found this github issues through a google search pointing me to reddit. Looking at it again, the comments there seem to also discuss ways to do this with file links on linux.

1 Like

Amazing! Thank you! I ended up using the solution in this comment. Here's the exact steps I followed for everyone who inevitably stumbles across this thread in the future:

1. make local cargo project
cargo new all-the-docs
2. re-import & inline std docs from main.rs

main.rs:

#[doc(inline)]
pub use std;

fn main() {
    println!("Hello, world!");
}
3. add all the crates whose docs you wanna browse to Cargo.toml

Cargo.toml:

[package]
name = "all-the-docs"
version = "0.1.0"
authors = ["username <username@example.org>"]
edition = "2018"

[dependencies]
rand = "0.8.3"
syn = "1.0.60"
quote = "1.0.8"
bitflags = "1.2.1"
serde = "1.0.123"
log = "0.4.14"
lazy_static = "1.4.0"
num-traits = "0.2.14"
regex = "1.4.3"
# and so on
4. generate the docs & open them locally
cargo doc --open

Now going to the PartialEq page in the local docs lists all of the implementations in the standard library and all of the crates!

5 Likes