Toml Example
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
- support
#[serde(default)],#[serde(default = "function_name")]attributes (serdefeature, opt-in) - provide
#[toml_example(default)],#[toml_example(default = 0)],#[toml_example(default = "default_string")]attributes - The order matter of attribute macro, if
#[serde(default = ..]and#[toml_example(default = ..)]existing at the same time with different value
Quick Example
use 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
to_toml_example; // write example to a file
let example = 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
= 0
# Config.b should be a string
= ""
# Optional Config.c is a number
# c = 0
# Config.d is a list of number
# d = [ 0, ]
# Config.e should be a number
= 7
# Config.f should be a string
= "seven"
# Config.g should be a number
= 7
# Config.h should be a string
= "seven"
Nesting Struct
A nesting struct wrap with Option<T>, Vec<T>, HashMap<String, T>, BTreeMap<String, T> are handled.
Please add #[toml_example(nesting)], or #[toml_example(nesting = prefix)] on the field.
#[toml_example(nesting)]
/// Service with specific port
Node::toml_example() will be following string.
# Services are running in the node
# Service with specific port
[]
# port should be a number
= 80
Will do later
- Set key for dict type nesting struct