Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Generate commented TOML configuration scaffold files from Rust structs and values.

License

Notifications You must be signed in to change notification settings

DiscreteTom/toml-scaffold

Repository files navigation

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

About

Generate commented TOML configuration scaffold files from Rust structs and values.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages