百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

cargo-public-api

> 包管理
开源

在版本发布和提交之间列出和比较 Rust 库的公共 API。通过 CI 或 CLI 检测 API 变更和 semver 违规。

565 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

在版本发布和提交之间列出和比较 Rust 库的公共 API。通过 CI 或 CLI 检测 API 变更和 semver 违规。

cargo-public-api

List and diff the public API of Rust library crates between releases and commits. Detect breaking API changes and semver violations via CI or a CLI. Relies on and automatically builds rustdoc JSON, for which a recent version of the Rust nightly toolchain must be installed.

Installation

Install the cargo public-api subcommand with a recent regular stable Rust toolchain:

bash
cargo +stable install cargo-public-api

Ensure nightly-2025-11-22 or later is installed (does not need to be the active toolchain) so cargo public-api can build rustdoc JSON for you:

bash
rustup install nightly --profile minimal

Usage

List the Public API

This example lists the public API of the regex crate. First we clone the repo:

bash
git clone https://github.com/rust-lang/regex ; cd regex

Now we can list the public API of regex by running

bash
cargo public-api

which will print the public API of regex with one line per public item in the API:

Diff the Public API

… Against a Specific Published Version

To diff the public API of the regex crate in the current directory against published version 1.6.0 on crates.io:

bash
cargo public-api diff 1.6.0

… Against the Latest Published Version

bash
cargo public-api diff latest

… Between Git Commits

bash
cargo public-api diff ref1..ref2

… 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]:

bash
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:

…

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

bash
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

bash
cargo test

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

bash
UPDATE_SNAPSHOTS=yes cargo test

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

Less Noisy Output

For completeness, items belonging to Blanket Implementations, Auto Trait Implementations, and Auto Derived Implementations, such as

  • impl Into for T where U: From
  • impl Sync for ...
  • impl Debug for ... / #[derive(Debug)]

are included in the list of public items by default. Use

  • --omit blanket-impls
  • --omit auto-trait-impls
  • --omit auto-derived-impls

respectively to omit such items from the output to make it much less noisy:

bash
cargo public-api --omit blanket-impls,auto-trait-impls,auto-derived-impls

For convenience you can also use -s (--simplified) to achieve the same thing. This is a shorter form of the above command:

bash
cargo public-api -sss

Compatibility Matrix

Version Understands the rustdoc JSON output of
0.52.x nightly-2025-11-22 —
0.50.x — 0.51.x nightly-2025-08-02 — nightly-2025-11-21
0.49.x nightly-2025-07-17 — nightly-2025-08-01
0.48.x nightly-2025-06-22 — nightly-2025-07-16
0.47.x nightly-2025-03-24 — nightly-2025-06-21
0.46.x nightly-2025-03-16 — nightly-2025-03-23
earlier versions see here

Contributing

See CONTRIBUTING.md.

Maintainers

  • Enselic
  • douweschulte
  • Emilgardis

Trademark Notice

"Rust" and "Cargo" are trademarks of the Rust Foundation. This project is not affiliated with, endorsed by, or otherwise associated with the Rust Project or Rust Foundation.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rustapicargocargo-plugincargo-subcommand

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类包管理
定价开源

> 相关工具

N
npm
Node.js 默认包管理器
P
pnpm
高效节省磁盘的 Node 包管理器
I
is-gif
Check if a Buffer/Uint8Array is a GIF image