After having used the clap crate for parsing command line arguments, I've found it very useful that the crate can automatically generate help strings for the options based on the doc comments of struct members.
I'm now looking into using the toml crate for parsing configuration files, and also for being able to spit out a template config file by serialising a struct, with default values for the user to adapt. In this latter case, it would be really helpful to have the same behaviour as clap, where each struct member could have its doc comment (if specified) placed into the TOML file as a comment above the property.
I can't seem to find a way to do this with the existing toml crate, or with the toml_edit variant. Is it possible to achieve this behaviour for TOML?
There is no macro that will carry over the comments to TOML that I know of. You'd have to do it yourself. There is schemars for generating a schema file instead. If that isn't sufficient on its own, there is likely a way you could read the schema and apply the comments to the generated file yourself to avoid having to write your own macro.
Is there a Rust way to get the doc comment attached to a struct member? If that's easy enough to do, I could probably put together something adequate for my needs.
afaik it requires writing a declarative macro. You can do it with a declarative macro but it is messy. In the future, my hope is we'll have improved declarative macros for this and/or comptime reflection.