Function doku::to_json_val [−][src]
pub fn to_json_val<T>(val: &T) -> String where
T: Document + Serialize,
Expand description
Generates a JSON 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_json_val(&Config::default());
doku::assert_doc!(r#"
{
// Database's host
"db_host": "localhost"
}
"#, doc);
For more control over the output format, please see: to_json_fmt_val()
.