cargo public-items
wrapper for this libraryYou might want the convenient cargo public-items
wrapper for this library. See https://github.com/Enselic/cargo-public-items.
List public items (the public API) of Rust library crates by analyzing the rustdoc JSON of the crates. Also supports diffing the public API between releases and commits.
The library comes with a thin bin wrapper that can be used to explore the capabilities of this library.
```bash
% cargo install public_items
% rustup install nightly ```
To list all items that form the public API of your Rust library:
```bash
% cd ~/src/your_library % RUSTDOCFLAGS='-Z unstable-options --output-format json' cargo +nightly doc --lib --no-deps
% publicitems ./target/doc/yourlibrary.json
pub mod publicitems
pub fn publicitems::Options::clone(&self) -> Options
pub fn publicitems::Options::default() -> Self
pub fn publicitems::PublicItem::clone(&self) -> PublicItem
pub fn publicitems::publicitemsfromrustdocjsonstr(rustdocjsonstr: &str, options: Options) -> Result
It is frequently of interest to know how the public API of a crate has changed. You can find this out by doing a diff between different versions of the same library. Again, cargo public-items
makes this more convenient, but it is straightforward enough without it.
```bash
% publicitems ./target/doc/yourlibrary.old.json ./target/doc/your_library.json Removed: (nothing)
Changed:
-pub fn publicitems::sortedpublicitemsfromrustdocjsonstr(rustdocjsonstr: &str) -> Result
Added: +pub fn publicitems::Options::clone(&self) -> Options +pub fn publicitems::Options::default() -> Self +pub struct publicitems::Options +pub struct field publicitems::Options::withblanketimplementations: bool ```
In general, output aims to be character-by-character identical to the textual parts of the regular cargo doc
HTML output. For example, this item has the following textual representation in the rendered HTML:
pub fn input_files<I, P>(&mut self, paths: I) -> &mut Self
where
I: IntoIterator<Item = P>,
P: AsRef<Path>,
and public_items
represent this item in the following manner:
pub fn bat::PrettyPrinter::input_files<I, P>(&mut self, paths: I) -> &mut Self where I: IntoIterator<Item = P>, P: AsRef<Path>
If we normalize by removing newline characters and adding some whitespace padding to get the alignment right for side-by-side comparison, we can see that they are exactly the same, except an irrelevant trailing comma:
pub fn input_files<I, P>(&mut self, paths: I) -> &mut Self where I: IntoIterator<Item = P>, P: AsRef<Path>,
pub fn bat::PrettyPrinter::input_files<I, P>(&mut self, paths: I) -> &mut Self where I: IntoIterator<Item = P>, P: AsRef<Path>
By default, blanket implementations such as impl<T> Any for T
, impl<T> Borrow<T> for T
, and impl<T, U> Into<U> for T where U: From<T>
are omitted from the list of public items of a crate. For the vast majority of use cases, blanket implementations are not of interest, and just creates noise.
If you want to include items of blanket implementations in the output, set Options::with_blanket_implementations
to true if you use the library, or pass --with-blanket-implementations
to public_items
.
Documentation can be found at docs.rs as usual. There are also some simple examples on how to use the library. The code for the thin bin wrapper might also be of interest.
Maintainers of Rust libraries that want to keep track of changes to their public API.
See [limitation]
labeled issues.
| public_items | Understands the rustdoc JSON output of | | ------------- | --------------------------------------- | | v0.7.x | nightly-2022-03-14 — | | v0.5.x | nightly-2022-02-23 — nightly-2022-03-13 | | v0.2.x | nightly-2022-01-19 — nightly-2022-02-22 | | v0.0.5 | nightly-2021-10-11 — nightly-2022-01-18 |