@@ -32,6 +32,24 @@ pub fn attribute_godot_dyn(input_decl: venial::Item) -> ParseResult<TokenStream>
32
32
) ;
33
33
} ;
34
34
35
+ let mut associated_types = vec ! [ ] ;
36
+ for impl_member in & decl. body_items {
37
+ let venial:: ImplMember :: AssocType ( associated_type) = impl_member else {
38
+ continue ;
39
+ } ;
40
+ let Some ( type_expr) = & associated_type. initializer_ty else {
41
+ continue ;
42
+ } ;
43
+ let type_name = & associated_type. name ;
44
+ associated_types. push ( quote ! { #type_name = #type_expr } )
45
+ }
46
+
47
+ let associated_impl = if associated_types. is_empty ( ) {
48
+ None
49
+ } else {
50
+ Some ( quote ! { <#( #associated_types, ) * >} )
51
+ } ;
52
+
35
53
let class_path = & decl. self_ty ;
36
54
let class_name_obj = util:: class_name_obj ( class_path) ; //&util::extract_typename(class_path));
37
55
let prv = quote ! { :: godot:: private } ;
@@ -41,25 +59,25 @@ pub fn attribute_godot_dyn(input_decl: venial::Item) -> ParseResult<TokenStream>
41
59
let new_code = quote ! {
42
60
#decl
43
61
44
- impl :: godot:: obj:: AsDyn <dyn #trait_path> for #class_path {
45
- fn dyn_upcast( & self ) -> & ( dyn #trait_path + ' static ) {
62
+ impl :: godot:: obj:: AsDyn <dyn #trait_path #associated_impl > for #class_path {
63
+ fn dyn_upcast( & self ) -> & ( dyn #trait_path #associated_impl + ' static ) {
46
64
self
47
65
}
48
66
49
- fn dyn_upcast_mut( & mut self ) -> & mut ( dyn #trait_path + ' static ) {
67
+ fn dyn_upcast_mut( & mut self ) -> & mut ( dyn #trait_path #associated_impl + ' static ) {
50
68
self
51
69
}
52
70
}
53
71
54
72
:: godot:: sys:: plugin_add!( __GODOT_PLUGIN_REGISTRY in #prv; #prv:: ClassPlugin {
55
73
class_name: #class_name_obj,
56
74
item: #prv:: PluginItem :: DynTraitImpl {
57
- dyn_trait_typeid: std:: any:: TypeId :: of:: <dyn #trait_path>( ) ,
75
+ dyn_trait_typeid: std:: any:: TypeId :: of:: <dyn #trait_path #associated_impl >( ) ,
58
76
erased_dynify_fn: {
59
77
fn dynify_fn( obj: :: godot:: obj:: Gd <:: godot:: classes:: Object >) -> #prv:: ErasedDynGd {
60
78
// SAFETY: runtime class type is statically known here and linked to the `class_name` field of the plugin.
61
79
let obj = unsafe { obj. try_cast:: <#class_path>( ) . unwrap_unchecked( ) } ;
62
- let obj = obj. into_dyn:: <dyn #trait_path>( ) ;
80
+ let obj = obj. into_dyn:: <dyn #trait_path #associated_impl >( ) ;
63
81
let obj = obj. upcast:: <:: godot:: classes:: Object >( ) ;
64
82
65
83
#prv:: ErasedDynGd {
@@ -76,4 +94,4 @@ pub fn attribute_godot_dyn(input_decl: venial::Item) -> ParseResult<TokenStream>
76
94
} ;
77
95
78
96
Ok ( new_code)
79
- }
97
+ }
0 commit comments