Open poljar opened 1 year ago
This is not possible, the macro can't access the docs of another item. What we could potentially do is use #[doc = include_str!("file.md")]
to deduplicate, which should work as long as the bindings are never published to crates.io.
Theoretically it is possible with more macro attributes, placed on the items that hold the actual documentation, but it would get really really messy so I'm not sure about that.
This is not possible, the macro can't access the docs of another item. What we could potentially do is use #[doc = include_str!("file.md")] to deduplicate
I suggested this to @Hywan if the former is not possible, though he seemed to prefer the former. Not sure if he had some idea to make this work or if he's aware of the trouble.
I think what would be the absolute best solution is making the UniFFI proc-macros powerful enough that you no longer need external binding crates that wrap the main crate at all, and can just put uniffi attributes on the regular Rust API to expose it to other languages, including documentation. But that's a ton of work.
I'll work on that in UniFFI. I self-assign this issue to myself so that I don't forget :-).
We have a bunch of documentation, while not being perfect, is usable enough over at the
matrix-sdk
crate.Sadly over after crossing the FFI boundary people on the Swift or Kotlin side of things won't see any of our docs. This will be the case even if we document the Uniffi based bindings.
Furthermore, it would be quite annoying to have to document things twice, once in the
matrix-sdk
crate, and once in the bindings.A solution to this problem could be a
uniffi
macro that takes the docstring from another method and re-exposes it over the FFI. This would mean that the types wouldn't necessarily be the same, i.e. the Rust typebool
would not be translated toBoolean
on the Kotlin side. I think that this would be a tolerable situation.The macro could look something like: