mozilla / cbindgen

A project for generating C bindings from Rust code
Mozilla Public License 2.0
2.29k stars 294 forks source link

Add a way to copy doc comments from a different item #896

Open segevfiner opened 8 months ago

segevfiner commented 8 months ago

When building a C API for an existing crate with a Rust centric API. You often write wrapper functions that wrap the Rust API into something suitable for C, e.g. boxing stuff into raw pointers, error handling, etc. I would be nice to be able to specify that cbindgen should copy the documentation comment of another item when generating the header so you can copy it from the original wrapped item without duplicating the comment in the code.

kriswuollett commented 7 months ago

Have same issue and tried a workaround that I expected to work. However cbindgen is not adding the contents of #[doc = include_str!("sample.md")] when applied to an enum variant, while a comment like /// sample is added to the enum variant definition in the C language output. I think the doc include string may be the most directly supported way in Rust to copy doc comments, whether or not an IDE supports it for tooltips?

However then I'd get into the issue of whether or not the target language supports Markdown in code comments.