6 releases

0.2.0 Oct 20, 2024
0.1.4 Dec 12, 2023
0.1.3 Nov 9, 2023

#647 in Development tools

Download history 6/week @ 2024-09-25 2/week @ 2024-10-02 1/week @ 2024-10-09 158/week @ 2024-10-16 18/week @ 2024-10-23 6/week @ 2024-10-30 7/week @ 2024-11-06

348 downloads per month

MIT/Apache

53KB
1.5K SLoC

crate-inspector

Inspect the public APIs of Rust library crates

Examples

Getting items

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);
}

Downcasting

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());
    }
}

License

This project is licensed under either of Apache License, Version 2.0 or MIT license at your option.

Dependencies

~3.5–4.5MB
~89K SLoC