toml-example-derive 0.6.0

A lib help generate toml example
Documentation

Toml Example

Crates.io MIT licensed Docs

A lib help generate toml example

Introduction

This crate provides the TomlExample trait and an accompanying derive macro.

Deriving TomlExample on a struct will provide to_example function help generate toml example file base documentation

Quick Example

use toml_example::TomlExample;

/// Config is to arrange something or change the controls on a computer or other device
/// so that it can be used in a particular way
#[derive(TomlExample)]
struct Config {
    /// Config.a should be a number
    a: usize,
    /// Config.b should be a string
    b: String,
    /// Optional Config.c is a number
    c: Option<usize>,
    /// Config.d is a list of number
    d: Vec<usize>,
    /// Config.e should be a number
    #[serde(default = "default_int")]
    e: usize,
    /// Config.f should be a string
    #[serde(default = "default_str")]
    f: String,
}
fn default_int() -> usize {
    7
}
fn default_str() -> String {
    "default".into()
}

Config::to_toml_example("example.toml");  // write example to a file
let example = Config::toml_example();

Toml example base on the doc string of each field

# Config is to arrange something or change the controls on a computer or other device
# so that it can be used in a particular way

# Config.a should be a number
a = 0
# Config.b should be a string
b = ""
# Optional Config.c is a number
# c = 0
# Config.d is a list of number
# d = [ 0, ]
# Config.e should be a number
e = 7
# Config.f should be a string
f = "default"

Will do later

  • nesting structure