toml-scaffold 0.2.1

Generate commented TOML scaffolds from Rust structs and values
Documentation

toml-scaffold

Crates.io License codecov

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 and serde_json::Value

Installation

Add the following dependencies to your Cargo.toml:

[dependencies]
serde = { version = "1", features = ["derive"] }
schemars = "1"
toml-scaffold = "0.2"

Usage

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

More Examples

CHANGELOG