Skip to content

Commit 8270899

Browse files
committed
Fix inconsistent enum name in bindings generator
Example: when using godot-rust with the VoxelTools engine module, the api.json has many nested 'Result' types. In some occurrences, these identifiers are prefixed with the containing class, e.g. VoxelStreamResult. However, some references to these type names are not using the prefixed identifier, thus creating compile errors: --------------------------------------------------------------------------------------------------------------------------------------------------------- error[E0425]: cannot find function, tuple struct or tuple variant `Result` in module `crate::generated::voxel_stream` --> <path>/target/<toolchain>/debug/build/gdnative-bindings-6c3842bd5f0b6d58/out/generated.rs:3963:2992 | 3963 | ... ; crate :: generated :: voxel_stream :: Result (ret) } } # [doc = ""] # [doc = ""] # [inline] pub fn get_block_size (& self) -> Vecto... | ^^^^^^ not found in `crate::generated::voxel_stream` ---------------------------------------------------------------------------------------------------------------------------------------------------------
1 parent c1c1354 commit 8270899

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

bindings_generator/src/api.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use heck::ToPascalCase as _;
1+
use super::classes::generate_enum_name;
2+
use miniserde::Deserialize;
23
use proc_macro2::TokenStream;
34
use quote::{format_ident, quote};
45
use std::collections::{HashMap, HashSet};
56

6-
use miniserde::Deserialize;
77
miniserde::make_place!(Place);
88

99
pub struct Api {
@@ -400,7 +400,8 @@ impl Ty {
400400
// Enums may reference known types (above list), check if it's a known type first
401401
let mut split = ty[5..].split("::");
402402
let class_name = split.next().unwrap();
403-
let name = format_ident!("{}", split.next().unwrap().to_pascal_case());
403+
let enum_raw_name = split.next().unwrap();
404+
let name = format_ident!("{}", generate_enum_name(class_name, enum_raw_name));
404405
let module = format_ident!("{}", module_name_from_class_name(class_name));
405406
// Is it a known type?
406407
match Ty::from_src(class_name) {

bindings_generator/src/classes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub(crate) fn generate_enums(class: &GodotClass) -> TokenStream {
143143
}
144144
}
145145

146-
fn generate_enum_name(class_name: &str, enum_name: &str) -> String {
146+
pub(crate) fn generate_enum_name(class_name: &str, enum_name: &str) -> String {
147147
// In order to not pollute the API with more Result types,
148148
// rename the Result enum used by Search to SearchResult.
149149
// to_pascal_case() is used to make the enums more rust-like.

0 commit comments

Comments
 (0)