Generate commented TOML configuration scaffold files from Rust structs and values.
- 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
Add the following dependencies to your Cargo.toml:
[dependencies]
serde = { version = "1", features = ["derive"] }
schemars = "1"
toml-scaffold = "0.2"use schemars::JsonSchema;
use serde::Serialize;
use toml_scaffold::TomlScaffold;
/// Server configuration
#[derive(Serialize, JsonSchema, TomlScaffold)]
struct Config {
/// Server host address
host: String,
/// Server port
port: u16,
}
fn main() {
let config = Config {
host: "localhost".to_string(),
port: 8080,
};
let scaffold = config.to_scaffold().unwrap();
println!("{}", scaffold);
}Output:
# Server configuration
# Server host address
host = "localhost"
# Server port
port = 8080