generated from ewpratten/rust-template
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
structs.rs
35 lines (27 loc) · 1.19 KB
/
structs.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use super::{raylib_api::RayLibApiDefinition, type_xlat::translate_c_type_to_rust};
pub fn wrap_exposed_structs(api_defs: RayLibApiDefinition) {
// Allocate an output buffer for lines
let mut lines = Vec::new();
// Handle each struct
for st in api_defs.structs {
// Write a doc comment with raylib's provided struct description
lines.push("".to_string());
lines.push(format!("/// {}", st.description));
// Write the struct definition
lines.push(format!("#[repr(C)]"));
lines.push(format!("pub struct {} {{", st.name));
// Write each field
for field in st.fields {
// Write a doc comment with raylib's provided field description
lines.push(format!(" /// {}", field.description));
// Write the field definition
lines.push(format!(" pub {}: {},", field.name, translate_c_type_to_rust(&field.kind)));
}
// Close the struct definition
lines.push(format!("}}"));
}
// Write the output file
let out_dir = std::env::var("OUT_DIR").unwrap();
let out_path = format!("{}/structs.rs", out_dir);
std::fs::write(out_path, lines.join("\n")).unwrap();
}