brk_bindgen/generators/
mod.rs1use std::{fmt::Write, fs, io, path::Path};
11
12pub mod javascript;
13pub mod python;
14pub mod rust;
15
16pub use javascript::generate_javascript_client;
17pub use python::generate_python_client;
18pub use rust::generate_rust_client;
19
20pub const MANUAL_GENERIC_TYPES: &[&str] = &["SeriesData", "SeriesEndpoint"];
22
23pub fn write_description(output: &mut String, desc: &str, prefix: &str, empty_prefix: &str) {
26 for line in desc.lines() {
27 if line.is_empty() {
28 writeln!(output, "{}", empty_prefix).unwrap();
29 } else {
30 writeln!(output, "{}{}", prefix, line).unwrap();
31 }
32 }
33}
34
35pub fn normalize_return_type(return_type: &str) -> String {
38 let mut result = return_type.to_string();
39 for type_name in MANUAL_GENERIC_TYPES {
40 result = result.replace(type_name, &format!("Any{}", type_name));
41 }
42 result
43}
44
45pub fn write_if_changed(path: &Path, content: &str) -> io::Result<()> {
48 if let Ok(existing) = fs::read_to_string(path)
49 && existing == content
50 {
51 return Ok(());
52 }
53 fs::write(path, content)
54}