https://github.com/awslabs/cargo-check-external-types

Static analysis tool for Rust library authors to set and verify which types from other libraries are allowed to be exposed in their public API.

https://github.com/awslabs/cargo-check-external-types

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.1%) to scientific vocabulary

Keywords from Contributors

diagram labels interaction
Last synced: 10 months ago · JSON representation

Repository

Static analysis tool for Rust library authors to set and verify which types from other libraries are allowed to be exposed in their public API.

Basic Info
Statistics
  • Stars: 59
  • Watchers: 6
  • Forks: 13
  • Open Issues: 6
  • Releases: 12
Created almost 4 years ago · Last pushed 11 months ago
Metadata Files
Readme Contributing License Code of conduct Codeowners

README.md

cargo-check-external-types

cargo-check-external-types is a static analysis tool for Rust library authors to set and verify which types from other libraries are allowed to be exposed in their public API. This is useful for ensuring that a breaking change to a dependency doesn't force a breaking change in the library that's using it.

The tool has two output formats to cover different use-cases:

  • errors (the default): Output error messages for each type that is exposed in the public API and exit with status 1 if there is at least one error. This is useful for continuous integration.
  • markdown-table: Output the places types are exposed as a Markdown table. This is intended as a discovery tool for established projects.

The tool has an optional configuration file where types can by explicitly allowed.

Example Output

The test suite has a Rust library that relies on some external types. When the tool is run against this library without any configuration, it emits errors for each occurrence of an external type in the public API.

When a config file is provided, the allowed external types no longer show up in the output.

When the output format is set to markdown-table, then a table of external types is output.

How to Use

Important: This tool requires a nightly build of Rust to be installed since it relies on the rustdoc JSON output, which hasn't been stabilized yet. The main branch was last tested against nightly-2025-08-06. For info on what nightly version a specific release depends on, see the releases page.

To install, run the following from this README path:

bash cargo install --locked cargo-check-external-types

Then, in your library crate path, run: bash cargo +nightly check-external-types

This will produce errors if any external types are used in a public API at all. That's not terribly useful on its own, so the tool can be given configuration in your crate's Cargo.toml to allow certain types. For example, we can allow any type in bytes by adding this metadata to your crate's Cargo.toml:

toml [package.metadata.cargo_check_external_types] allowed_external_types = ["bytes::*"]

Or, if you'd prefer, you can create a separate configuration file with the content:

toml allowed_external_types = [ "bytes::*", ]

Save that file somewhere in your project (in this example, we choose the name external-types.toml), and then run the command with:

bash cargo +nightly check-external-types --config external-types.toml

If both a Cargo.toml package metadata section and a --config flag are provided, the --config flag will be used instead of the package metadata.

Caveats

When public types and modules declared inside a #[doc(hidden)] module are reexported from a public module, they aren't checked for external types. This is because of how they are recorded in RustDoc's index. When such types and modules are encountered by this tool, a warning will be logged.

Updating rustdoc-types and the Rust toolchain version

rustdoc-types defines an unstable JSON format that this tool is based on. When updating rustdoc-types, the Rust toolchain version must be updated to a nightly version that supports the version of the JSON format being used.

It's usually enough to update the toolchain to whatever the most recent nightly version is. All in all, you must update:

  • The rustdoc-types dependency in Cargo.toml to the new version.
  • The rust-toolchain file to point to the new nightly version.
  • The README.md file, specifically the "It was last tested against nightly-XXXX-XX-XX." of the "How to Use" section.
  • The rust_version in the CI workflow file.

Then, PR your changes.

Security

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

Owner

  • Name: Amazon Web Services - Labs
  • Login: awslabs
  • Kind: organization
  • Location: Seattle, WA

AWS Labs

GitHub Events

Total
  • Create event: 40
  • Issues event: 2
  • Release event: 2
  • Watch event: 20
  • Delete event: 40
  • Issue comment event: 30
  • Push event: 46
  • Pull request review comment event: 5
  • Pull request review event: 28
  • Pull request event: 76
  • Fork event: 4
Last Year
  • Create event: 40
  • Issues event: 2
  • Release event: 2
  • Watch event: 20
  • Delete event: 40
  • Issue comment event: 30
  • Push event: 46
  • Pull request review comment event: 5
  • Pull request review event: 28
  • Pull request event: 76
  • Fork event: 4

Committers

Last synced: about 3 years ago

All Time
  • Total Commits: 64
  • Total Committers: 4
  • Avg Commits per committer: 16.0
  • Development Distribution Score (DDS): 0.297
Past Year
  • Commits: 64
  • Committers: 4
  • Avg Commits per committer: 16.0
  • Development Distribution Score (DDS): 0.297
Top Committers
Name Email Commits
dependabot[bot] 4****]@u****m 45
John DiSanti j****i@a****m 17
Amazon GitHub Automation 5****o@u****m 1
Taiki Endo t****9@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 9
  • Total pull requests: 188
  • Average time to close issues: 3 months
  • Average time to close pull requests: 10 days
  • Total issue authors: 7
  • Total pull request authors: 16
  • Average comments per issue: 1.22
  • Average comments per pull request: 0.52
  • Merged pull requests: 119
  • Bot issues: 0
  • Bot pull requests: 154
Past Year
  • Issues: 1
  • Pull requests: 26
  • Average time to close issues: 4 months
  • Average time to close pull requests: 23 days
  • Issue authors: 1
  • Pull request authors: 6
  • Average comments per issue: 2.0
  • Average comments per pull request: 0.23
  • Merged pull requests: 7
  • Bot issues: 0
  • Bot pull requests: 20
Top Authors
Issue Authors
  • jdisanti (3)
  • dependabot[bot] (2)
  • baldoalessandro (1)
  • thomaseizinger (1)
  • cpu (1)
  • connec (1)
  • djc (1)
  • BiagioFesta (1)
Pull Request Authors
  • dependabot[bot] (196)
  • jdisanti (12)
  • Velfi (7)
  • tottoto (4)
  • eopb (2)
  • cpu (2)
  • aajtodd (2)
  • taiki-e (2)
  • Hmikihiro (2)
  • matthiasbeyer (2)
  • kdnakt (2)
  • jayvdb (1)
  • landonxjames (1)
  • tshepang (1)
  • rcoh (1)
Top Labels
Issue Labels
enhancement (3) good first issue (2) dependencies (2) bug (1)
Pull Request Labels
dependencies (196) rust (11)

Packages

  • Total packages: 1
  • Total downloads:
    • cargo 84,272 total
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 17
  • Total maintainers: 2
crates.io: cargo-check-external-types

Static analysis tool to detect external types exposed in a library's public API.

  • Versions: 17
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 84,272 Total
Rankings
Downloads: 15.4%
Dependent repos count: 29.3%
Average: 29.6%
Stargazers count: 32.1%
Dependent packages count: 33.8%
Forks count: 37.5%
Maintainers (2)
Last synced: 11 months ago

Dependencies

Cargo.lock cargo
  • anyhow 1.0.66
  • atty 0.2.14
  • autocfg 1.1.0
  • bitflags 1.3.2
  • camino 1.1.1
  • cargo-platform 0.1.2
  • cargo_metadata 0.15.0
  • cfg-if 1.0.0
  • clap 3.1.18
  • clap_derive 3.1.18
  • clap_lex 0.2.4
  • ctor 0.1.23
  • diff 0.1.13
  • hashbrown 0.12.3
  • heck 0.4.0
  • hermit-abi 0.1.19
  • indexmap 1.9.1
  • is_ci 1.1.1
  • itoa 1.0.3
  • lazy_static 1.4.0
  • libc 0.2.132
  • log 0.4.17
  • matchers 0.1.0
  • nu-ansi-term 0.46.0
  • once_cell 1.13.1
  • os_str_bytes 6.3.0
  • output_vt100 0.1.3
  • overload 0.1.1
  • owo-colors 3.5.0
  • pest 2.4.0
  • pin-project-lite 0.2.9
  • pretty_assertions 1.3.0
  • proc-macro-error 1.0.4
  • proc-macro-error-attr 1.0.4
  • proc-macro2 1.0.43
  • quote 1.0.21
  • regex 1.6.0
  • regex-automata 0.1.10
  • regex-syntax 0.6.27
  • rustdoc-types 0.12.0
  • ryu 1.0.11
  • semver 1.0.13
  • serde 1.0.147
  • serde_derive 1.0.147
  • serde_json 1.0.87
  • sharded-slab 0.1.4
  • smallvec 1.9.0
  • strsim 0.10.0
  • supports-color 1.3.0
  • syn 1.0.99
  • termcolor 1.1.3
  • test_bin 0.4.0
  • textwrap 0.15.0
  • thiserror 1.0.32
  • thiserror-impl 1.0.32
  • thread_local 1.1.4
  • toml 0.5.9
  • tracing 0.1.37
  • tracing-attributes 0.1.23
  • tracing-core 0.1.30
  • tracing-log 0.1.3
  • tracing-subscriber 0.3.16
  • ucd-trie 0.1.4
  • unicode-ident 1.0.3
  • valuable 0.1.0
  • version_check 0.9.4
  • wildmatch 2.1.1
  • winapi 0.3.9
  • winapi-i686-pc-windows-gnu 0.4.0
  • winapi-util 0.1.5
  • winapi-x86_64-pc-windows-gnu 0.4.0
  • yansi 0.5.1
Cargo.toml cargo
  • pretty_assertions 1.3 development
  • test_bin 0.4 development
  • anyhow 1
  • cargo_metadata 0.15
  • clap ~3.1.18
  • owo-colors 3
  • pest 2
  • rustdoc-types 0.12
  • serde 1
  • serde_json 1
  • toml 0.5
  • tracing 0.1
  • tracing-attributes 0.1
  • tracing-subscriber 0.3.16
  • wildmatch 2
.github/workflows/ci.yml actions
  • Swatinem/rust-cache 842ef286fff290e445b90b4002cc9807c3669641 composite
  • actions-rs/toolchain v1 composite
  • actions/checkout v3 composite
  • re-actors/alls-green 3a2de129f0713010a71314c74e33c0e3ef90e696 composite
test-workspace/Cargo.toml cargo
test-workspace/external-lib/Cargo.toml cargo
test-workspace/test-crate/Cargo.toml cargo
test-workspace/test-crate-custom-lib-name/Cargo.toml cargo
test-workspace/test-crate-metadata-config/Cargo.toml cargo
test-workspace/test-reexports-crate/Cargo.toml cargo
test-workspace/test-type-exported-from-hidden-module/Cargo.toml cargo