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 a Rust library crate by analyzing the rustdoc JSON of the crate. Enables diffing public API between releases and commits.
If you prefer not to use the convenient cargo public-items
wrapper you can play around with the thin public_items
bin wrapper around this library. Do like this:
```bash
public_items
librarycargo install public_items
cd ~/src/your_library RUSTDOCFLAGS='-Z unstable-options --output-format json' cargo +nightly doc --lib --no-deps
publicitems ./target/doc/yourlibrary.json ```
public_items
library itselftxt
% git clone https://github.com/Enselic/public_items.git
% cd public_items
% RUSTDOCFLAGS='-Z unstable-options --output-format json' cargo +nightly doc --lib --no-deps
% public_items ./target/doc/public_items.json
pub enum public_items::Error
pub enum variant public_items::Error::SerdeJsonError(serde_json::Error)
pub fn public_items::Error::fmt(&self, __formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
pub fn public_items::Error::fmt(&self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result
pub fn public_items::Error::from(source: serde_json::Error) -> Self
pub fn public_items::Error::source(&self) -> std::option::Option<&std::error::Error + 'static>
pub fn public_items::Options::clone(&self) -> Options
pub fn public_items::Options::default() -> Self
pub fn public_items::Options::fmt(&self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result
pub fn public_items::PublicItem::cmp(&self, other: &PublicItem) -> $crate::cmp::Ordering
pub fn public_items::PublicItem::eq(&self, other: &PublicItem) -> bool
pub fn public_items::PublicItem::fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
pub fn public_items::PublicItem::ne(&self, other: &PublicItem) -> bool
pub fn public_items::PublicItem::partial_cmp(&self, other: &PublicItem) -> $crate::option::Option<$crate::cmp::Ordering>
pub fn public_items::sorted_public_items_from_rustdoc_json_str(rustdoc_json_str: &str, options: Options) -> Result<Vec<PublicItem>>
pub mod public_items
pub struct public_items::Options
pub struct public_items::PublicItem
pub struct field public_items::Options::with_blanket_implementations: bool
pub type public_items::Result<T> = std::result::Result<T, Error>
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>
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. This example does a diff between publicitems v0.2.0 and publicitems v0.4.0:
``` % cd ~/src/publicitems % git checkout v0.4.0 % RUSTDOCFLAGS='-Z unstable-options --output-format json' cargo +nightly doc --lib --no-deps % cp ./target/doc/publicitems.json /tmp/publicitems-v0.2.0.json % git checkout v0.4.0 % RUSTDOCFLAGS='-Z unstable-options --output-format json' cargo +nightly doc --lib --no-deps % cp ./target/doc/publicitems.json /tmp/publicitems-v0.4.0.json % publicitems /tmp/publicitems-v0.2.0.json /tmp/publicitems-v0.4.0.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 fn publicitems::Options::fmt(&self, f: &mut $crate::fmt::Formatter<'>) -> $crate::fmt::Result +pub struct publicitems::Options +pub struct field publicitems::Options::withblanketimplementations: bool
```
Documentation can be found at docs.rs as usual.
The most comprehensive example code is the code for the thin wrapper around the library. There are also some examples.
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
.
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 |