Thanks to visit codestin.com
Credit goes to lib.rs

#rustdoc-json #diff #semver

public-api

List and diff the public API of Rust library crates. Relies on rustdoc JSON output from the nightly toolchain.

71 releases (39 breaking)

Uses new Rust 2024

0.50.3 Jan 22, 2026
0.50.2 Dec 19, 2025
0.50.1 Aug 11, 2025
0.49.0 Jul 17, 2025
0.12.4 Jul 24, 2022

#3 in #rustdoc-json

Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App

6,780 downloads per month
Used in 31 crates (24 directly)

MIT license

105KB
2K SLoC

public-api

List and diff the public API of Rust library crates by analyzing rustdoc JSON output files from rustdoc +nightly.

Usage

… as a Rust library

See docs.rs for library documentation and example code.

… as a CLI

Use cargo public-api for CLI use cases.

… as a CI Check

With a regular cargo test that you run in CI you will be able to

  • prevent accidental changes to your public API
  • review the public API diff of deliberate changes

First add the latest versions of the recommended libraries to your [dev-dependencies]:

cargo add --dev \
    rustup-toolchain \
    rustdoc-json \
    public-api

Then add the following test to your project. As the author of the below test code, I hereby associate it with CC0 and to the extent possible under law waive all copyright and related or neighboring rights to it:

#[test]
fn public_api() {
    // Install a compatible nightly toolchain if it is missing.
    rustup_toolchain::install(public_api::MINIMUM_NIGHTLY_RUST_VERSION).unwrap();

    // Build rustdoc JSON.
    let rustdoc_json = rustdoc_json::Builder::default()
        .toolchain(public_api::MINIMUM_NIGHTLY_RUST_VERSION)
        .build()
        .unwrap();

    // Derive the public API from rustdoc JSON.
    let public_api = public_api::Builder::from_rustdoc_json(rustdoc_json)
        .build()
        .unwrap();

    // Assert that the public API matches the latest snapshot.
    // Run with env var `UPDATE_SNAPSHOTS=yes` to update the snapshot.
    public_api.assert_eq_or_update("./tests/snapshots/public-api.txt");
}

Before you run the test the first time you need create a snapshot of the current public API:

UPDATE_SNAPSHOTS=yes cargo test

This creates a tests/public-api.txt file in your project that you git add together with your other project files. Then a regular

cargo test

will fail if your public API is accidentally or deliberately changed. Run

UPDATE_SNAPSHOTS=yes cargo test

again to update the public API snapshot and review the git diff.

Maintainers

See here.

Dependencies

~1–12MB
~93K SLoC