mod field_path;
mod format;
mod schema;
use field_path::FieldPath;
use schemars::JsonSchema;
use serde::Serialize;
pub use toml_scaffold_macros::TomlScaffold;
pub trait TomlScaffold: Serialize + JsonSchema {
fn to_scaffold(&self) -> Result<String, toml::ser::Error> {
let value = toml::Value::try_from(&self)?;
let schema = schemars::schema_for!(Self);
let schema_info = schema::extract_schema_info(&schema, &FieldPath::new());
let result = format::format_with_comments(
&value,
&schema_info.comments,
&schema_info.all_fields,
&schema_info.optional_fields,
&FieldPath::new(),
);
Ok(format!("{}\n", result.trim_end()))
}
}