toml_example/traits.rs
1use std::fs::File;
2use std::io::prelude::*;
3use std::path::Path;
4
5pub trait TomlExample {
6 /// structure to toml example
7 fn toml_example() -> String;
8
9 /// structure, which is nesting or flatten inside other structure, to a toml example
10 /// There will be a section `{label_format.0}{label}{label_format.1}` for the example of struct, and `prefix` will add `# ` if it is a optional.
11 fn toml_example_with_prefix(label: &str, label_format: (&str, &str), prefix: &str) -> String;
12
13 fn to_toml_example<P: AsRef<Path>>(file_name: P) -> std::io::Result<()> {
14 let mut file = File::create(file_name)?;
15 file.write_all(Self::toml_example().as_bytes())?;
16 Ok(())
17 }
18}