Function doku::to_toml_val
source · pub fn to_toml_val<T>(val: &T) -> Stringwhere
T: Document + Serialize,
Expand description
Generates a TOML documentation for specified type, extracting example values from given serializable object.
This is useful e.g. if you’ve got a configuration with predefined values that you’d like to show your users.
Example
use doku::Document;
use serde::Serialize;
#[derive(Serialize, Document)]
struct Config {
/// Database's host
db_host: String,
}
impl Default for Config {
fn default() -> Self {
Self {
db_host: "localhost".to_string(),
}
}
}
let doc = doku::to_toml_val(&Config::default());
doku::assert_doc!(r#"
# Database's host
db_host = "localhost"
"#, doc);
For more control over the output format, please see: to_toml_fmt_val()
.