Consider this public API:
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct S {
i: i32,
}
With cargo public-api --simplified
the public API is reported as being:
pub mod api_test
pub struct api_test::S
impl core::clone::Clone for api_test::S
pub fn api_test::S::clone(&self) -> api_test::S
impl core::fmt::Debug for api_test::S
pub fn api_test::S::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
impl core::cmp::Eq for api_test::S
impl core::cmp::Ord for api_test::S
pub fn api_test::S::cmp(&self, other: &api_test::S) -> core::cmp::Ordering
impl core::cmp::PartialEq<api_test::S> for api_test::S
pub fn api_test::S::eq(&self, other: &api_test::S) -> bool
impl core::cmp::PartialOrd<api_test::S> for api_test::S
pub fn api_test::S::partial_cmp(&self, other: &api_test::S) -> core::option::Option<core::cmp::Ordering>
impl core::marker::StructuralEq for api_test::S
impl core::marker::StructuralPartialEq for api_test::S
which, while correct, is a bit noisy. I think there would be utility in adding a way for automatically derived impl
s to be omitted from the output, to make the output less noisy.
I propose that if --simplified
(short from -s
) is used twice, we skip automatically derived impl
s. So the CLI and its output would be:
$ cargo public-api -ss
pub mod api_test
pub struct api_test::S
The code to exclude automatically derived impl
s is:
diff --git a/public-api/src/item_processor.rs b/public-api/src/item_processor.rs
index 136ca3f..6df32fc 100644
--- a/public-api/src/item_processor.rs
+++ b/public-api/src/item_processor.rs
@@ -170,7 +170,9 @@ impl<'c> ItemProcessor<'c> {
item: &'c Item,
impl_: &'c Impl,
) {
- if !ImplKind::from(impl_).is_active(self.options) {
+ if !ImplKind::from(impl_).is_active(self.options)
+ || item.attrs.iter().any(|a| a == "#[automatically_derived]")
+ {
return;
}
but we need to:
- Move it inside of
ImplKind::from()
to make the code look nicer
- Figure out how to enable multiple
--simplified
with clap v4 derive (From here: "Replaced Arg::multiple_occurrences
with ArgAction::Append
or ArgAction::Count
")
- Add
public_api::Options::skip_automatically_derived: bool
and set if if --simplified
is used twice
Should be pretty straight-forward, so setting good-first-issue.
enhancement good first issue