toml-scaffold
Generate commented TOML configuration scaffold files from Rust structs and values.
Features
- Preserve doc comments as TOML comments
- Preserve field order in generated TOML
- Support for common types: primitives,
Option,HashMap,Vec, nested structs andserde_json::Value - Customizable formatting with
#[format]attribute
Installation
Add the following dependencies to your Cargo.toml:
[]
= { = "1", = ["derive"] }
= "1"
= "0.4"
Usage
Basic Example
use JsonSchema;
use Serialize;
use TomlScaffold;
/// Server configuration
Output:
# Server configuration
# Server host address
= "localhost"
# Server port
= 8080
Custom Formatting
Use #[format = "..."] to control how fields are rendered:
use JsonSchema;
use Serialize;
use TomlScaffold;
Output:
= "myapp"
= { = "localhost", = 5432 }
= "0.0.0.0"
= 8080
[]
= 123
= 456
Format Options:
"inline"- Inline table:{ key = value }"dotted"- Flatten one level:field.key = value"dotted-nested"- Recursively flatten:field.key.subkey = value"*dotted"- Keep[field]section, flatten children"*dotted-nested"- Keep[field]section, recursively flatten children"multiline"- Force multiline array format