Any way to specify docs for derive?

Can one make it so e.g. a derive(Default) has custom docs?

For example here's a derive(Default) today: RangeFull in std::ops - Rust but is there any way to make it have both custom impl-level docs and fn-level docs?

Yes, when the proc macro generates the trait impl, the library author would have the option to add whatever doc-comments they want by including them in the generated code.

I don't think you can do this with the built-in derive(Default). You'll need to switch to a manual impl Default to customize the docs.

So never the user?

The author of the custom derive is the one generating the Default impl so they would need to explicitly give you a mechanism to add your own doc-comments.

If this is important to you then you can always write the Default implementation yourself. That might be easier than trying to shoehorn something into the existing #[derive(Default)].

1 Like

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.