Serialising a struct to TOML along with its doc comments

⚓ Rust    📅 2025-12-26    👤 surdeus    👁️ 1      

surdeus

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?

1 post - 1 participant

Read full topic

🏷️ Rust_feed