Reusing documentation of another function?

I have a wrap function of an original function. Both have the same semantic meaning and signature.
Is it possible to reuse documentation of the original function for the wrap function instead of duplicating it?

You can put the documentation in a separate file and include it in the definition of each function.

1 Like

Hi Alice. Thanks for the response.
Too over complicated.
Maybe there is a way without splitting the file?

There isn't.

Well.. procedural macro would work.
But such procedural macro would be very slow..

Ah, well, that is a point. you could define a macro that puts the same documentation on every function defined in it. Doesn't have to be procedural.

Did you mean generating that?

#[doc = $x]

Not sure declarative macros work well with attributes.

It can be done.

You could link to the other function. Seems like the reader would understand.

/// This function has the same semantics as  [`other_function`](path/to/other/function),
/// please refer to  [`other_function`](path/to/other/function).
3 Likes

That's a good option. Thanks @stonerfish!

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.