Have a derive macro produce a link to a generated trait

I have a derive macro that, when applied to Foo produces something like:

pub trait Foo_Getters<'a> {
    fn something();
impl<'a> Foo_Getters for Handle<'a, Foo> {
    fn something() { ... }

(Foo is in the user's crate, and Handle is in my lib's crate. That's why I need to go through a trait).
Now there are a lot of these Foo in a user's crate, and a lot of these traits which appear disconnected in the rustdoc.

I would like to offer information to someone browsing the doc for Foo, telling them "Did you know that you can do all these something()s with a Handle<Foo> ?

How can I do that ? A simple link to the trait's doc is fine, as there is not much else in the Foo structs doc. But I couldn't manage to include that (I tried to produce an associated type).

Not sure if this is exactly what you're looking for, but you can generate documentation from proc-macros by emitting #[doc] attributes.

Here's an example where I generate documentation for a generated inherent method on a type that points to a generic version on an automatically implemented trait (using the quote crate).

1 Like

This sounds like exactly what I need, thanks!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.