crate-inspector

Crates.iocrate-inspector
lib.rscrate-inspector
version0.2.0
sourcesrc
created_at2023-11-08 08:08:30.002318
updated_at2024-10-20 09:38:42.116115
descriptionA library to inspect the public APIs of Rust crates
homepage
repositoryhttps://github.com/mtshiba/crate-inspector
max_upload_size
id1028843
size75,755
Shunsuke Shibayama (mtshiba)

documentation

https://docs.rs/crate-inspector

README

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.

Commit count: 21

cargo fmt