cargo-public-api icon indicating copy to clipboard operation
cargo-public-api copied to clipboard

Present associated items as part of `impl`s

Open Enselic opened this issue 3 years ago • 1 comments

If a struct Foo implements both e.g. TryFrom and TryInto, the output will contain

pub type some_crate::Foo::Error
pub type some_crate::Foo::Error

This is because both TryFrom and TryInto has an associated type called Error.

The output should be more specific about where the Error comes from in each case, to make it clear it is not a matter of duplication.

Enselic avatar Feb 13 '22 17:02 Enselic

cargo doc HTML does not present these in isolation, but as part of impls. We show this:

% cd test-apis/example_api-v0.1.0
% cargo public-api --with-blanket-implementations
[...]
pub type example_api::Struct::Error = <U as TryFrom<T>>::Error
pub type example_api::Struct::Error = Infallible

i.e. the associated types are by themselves. That doesn't make them very "associated".

If we compare to cargo doc HTML, it looks like this:

% cargo doc --open
Skärmavbild 2022-07-03 kl  21 15 38

If you minimize an impl, the Error also goes away, and the impl has a larger font. Clearly (but perhaps not obviously) the Error is presented as part of an impl. So I think the right way to solve this is to also include impls in our output. impls are also items, after all.

This is highly related to

  • #36
  • #38

Enselic avatar Jul 03 '22 19:07 Enselic