xref: /third_party/rust/crates/syn/codegen/src/json.rs (revision fad3a1d3)
1use crate::workspace_path;
2use anyhow::Result;
3use std::fs;
4use syn_codegen::Definitions;
5
6pub fn generate(defs: &Definitions) -> Result<()> {
7    let mut j = serde_json::to_string_pretty(&defs)?;
8    j.push('\n');
9
10    let check: Definitions = serde_json::from_str(&j)?;
11    assert_eq!(*defs, check);
12
13    let json_path = workspace_path::get("syn.json");
14    fs::write(json_path, j)?;
15
16    Ok(())
17}
18