Crates.io | crate-inspector |
lib.rs | crate-inspector |
version | 0.4.0 |
created_at | 2023-11-08 08:08:30.002318+00 |
updated_at | 2025-08-12 01:22:07.688002+00 |
description | A library to inspect the public APIs of Rust crates |
homepage | |
repository | https://github.com/mtshiba/crate-inspector |
max_upload_size | |
id | 1028843 |
size | 83,276 |
crate-inspector
Inspect the public APIs of Rust library crates
This crate requires that you have the nightly Rust toolchain installed, as it uses the latest rustdoc
API (and does not require compiling with the nightly toolchain).
use crate_inspector::CrateBuilder;
let builder = CrateBuilder::default()
.toolchain("nightly")
.manifest_path("Cargo.toml");
let krate = builder.build().unwrap();
for item in krate.items() {
println!("item: {:?}", item.name);
}
for strc in krate.structs() {
println!("struct: {}", strc.name());
println!("#impls: {}", strc.impls().count());
}
for enm in krate.enums() {
println!("enum: {}", enm.name());
println!("variants: {:?}", enm.variants().collect::<Vec<_>>());
println!("#methods: {}", enm.impls().fold(0, |acc, i| acc + i.functions().count()));
}
for sub in krate.sub_modules() {
println!("submodule: {}", sub.name());
}
if let Some(foo) = krate.get_item("foo") {
println!("id: {:?}", foo.id);
}
use crate_inspector::{CrateBuilder, StructItem};
let builder = CrateBuilder::default()
.toolchain("nightly")
.manifest_path("Cargo.toml");
let krate = builder.build().unwrap();
for item in krate.items() {
if let Some(strc) = krate.downcast::<StructItem>(item) {
println!("struct: {}", strc.name());
}
}
This crate depends on rustdoc's public API.
Here is a table mapping crate-inspector versions to corresponding rustdoc versions:
crate-inspector | rustdoc-types |
---|---|
0.1 | 0.23 |
0.2 | 0.32 |
0.3 | 0.54 |
0.4 | 0.55 |
This project is licensed under either of Apache License, Version 2.0 or MIT license at your option.