@@ -5,7 +5,7 @@ use paste::paste;
55use uniffi_bindgen:: interface:: Type ;
66
77use super :: oracle:: { AsCodeType , DartCodeOracle } ;
8- use crate :: gen:: render:: { Renderable , TypeHelperRenderer } ;
8+ use crate :: gen:: render:: { AsRenderable , Renderable , TypeHelperRenderer } ;
99
1010macro_rules! impl_code_type_for_compound {
1111 ( $T: ty, $type_label_pattern: literal, $canonical_name_pattern: literal) => {
@@ -47,7 +47,13 @@ macro_rules! impl_renderable_for_compound {
4747 let inner_codetype = DartCodeOracle :: find( self . inner( ) ) ;
4848 let inner_type_label = inner_codetype. type_label( ) ;
4949
50- type_helper. include_once_check( & inner_codetype. canonical_name( ) , & self . inner( ) ) ; // Add the Inner FFI Converter
50+ // Add the Inner FFI Converter and ensure it's rendered
51+ let inner_type_rendered = if !type_helper. include_once_check( & inner_codetype. canonical_name( ) , & self . inner( ) ) {
52+ // If this is the first time we're seeing this inner type, render it now
53+ self . inner( ) . as_renderable( ) . render_type_helper( type_helper)
54+ } else {
55+ quote!( )
56+ } ;
5157
5258 let cl_name = & format!( $canonical_name_pattern, & inner_codetype. canonical_name( ) ) ;
5359 let type_label = & format!( $type_label_pattern, & inner_type_label) ;
@@ -58,6 +64,8 @@ macro_rules! impl_renderable_for_compound {
5864
5965
6066 quote! {
67+ $inner_type_rendered
68+
6169 class $cl_name {
6270
6371 static $type_label lift( RustBuffer buf) {
@@ -124,7 +132,13 @@ macro_rules! impl_renderable_for_compound {
124132 let inner_codetype = self . inner( ) . as_codetype( ) ;
125133 let inner_type_label = inner_codetype. type_label( ) ;
126134
127- type_helper. include_once_check( & inner_codetype. canonical_name( ) , & self . inner( ) ) ; // Add the Inner FFI Converter
135+ // Add the Inner FFI Converter and ensure it's rendered
136+ let inner_type_rendered = if !type_helper. include_once_check( & inner_codetype. canonical_name( ) , & self . inner( ) ) {
137+ // If this is the first time we're seeing this inner type, render it now
138+ self . inner( ) . as_renderable( ) . render_type_helper( type_helper)
139+ } else {
140+ quote!( )
141+ } ;
128142
129143 let cl_name = & format!( $canonical_name_pattern, & inner_codetype. canonical_name( ) ) ;
130144 let type_label = & format!( "List<{}>" , & inner_type_label) ;
@@ -135,6 +149,8 @@ macro_rules! impl_renderable_for_compound {
135149
136150
137151 quote! {
152+ $inner_type_rendered
153+
138154 class $cl_name {
139155
140156 static $type_label lift( RustBuffer buf) {
@@ -233,8 +249,17 @@ impl Renderable for MapCodeType {
233249 let key_codetype = DartCodeOracle :: find ( self . key ( ) ) ;
234250 let val_codetype = DartCodeOracle :: find ( self . value ( ) ) ;
235251
236- type_helper. include_once_check ( & key_codetype. canonical_name ( ) , self . key ( ) ) ;
237- type_helper. include_once_check ( & val_codetype. canonical_name ( ) , self . value ( ) ) ;
252+ // Add the key and value FFI Converters and ensure they're rendered
253+ let key_type_rendered = if !type_helper. include_once_check ( & key_codetype. canonical_name ( ) , self . key ( ) ) {
254+ self . key ( ) . as_renderable ( ) . render_type_helper ( type_helper)
255+ } else {
256+ quote ! ( )
257+ } ;
258+ let val_type_rendered = if !type_helper. include_once_check ( & val_codetype. canonical_name ( ) , self . value ( ) ) {
259+ self . value ( ) . as_renderable ( ) . render_type_helper ( type_helper)
260+ } else {
261+ quote ! ( )
262+ } ;
238263
239264 let cl_name = & self . ffi_converter_name ( ) ;
240265 let key_type_label_owned = key_codetype. type_label ( ) ;
@@ -248,6 +273,9 @@ impl Renderable for MapCodeType {
248273 let val_conv = & val_conv_owned;
249274
250275 quote ! {
276+ $key_type_rendered
277+ $val_type_rendered
278+
251279 class $cl_name {
252280 static Map <$key_type_label, $val_type_label> lift( RustBuffer buf) {
253281 return $cl_name. read( buf. asUint8List( ) ) . value;
0 commit comments