@@ -259,10 +259,17 @@ fn get_bufferfish_write_fn(ty: Type, value_accessor: &str) -> String {
259259 if let Some ( GenericArgument :: Type ( inner_ty) ) = args. args . first ( ) {
260260 let inner_write_fn = get_element_write_fn ( inner_ty. clone ( ) ) ;
261261
262- return format ! (
263- "bf.writeUint16({0}.length)\n for (const item of {0}) {{\n bf.{1}(item)\n }}" ,
264- value_accessor, inner_write_fn
265- ) ;
262+ if is_primitive_type ( inner_ty) {
263+ return format ! (
264+ "bf.writeUint16({0}.length)\n for (const item of {0}) {{\n bf.{1}(item)\n }}" ,
265+ value_accessor, inner_write_fn
266+ ) ;
267+ } else {
268+ return format ! (
269+ "bf.writeUint16({0}.length)\n for (const item of {0}) {{\n {1}(bf, item)\n }}" ,
270+ value_accessor, inner_write_fn
271+ ) ;
272+ }
266273 }
267274 }
268275 }
@@ -290,12 +297,21 @@ fn get_bufferfish_write_fn(ty: Type, value_accessor: &str) -> String {
290297
291298fn is_primitive_type ( ty : & Type ) -> bool {
292299 if let Type :: Path ( TypePath { path, .. } ) = ty {
293- match path. get_ident ( ) . map ( |ident| ident. to_string ( ) ) . as_deref ( ) {
294- Some ( "u8" ) | Some ( "u16" ) | Some ( "u32" ) | Some ( "u64" ) | Some ( "u128" ) | Some ( "i8" )
295- | Some ( "i16" ) | Some ( "i32" ) | Some ( "i64" ) | Some ( "i128" ) | Some ( "bool" )
296- | Some ( "String" ) => true ,
297- _ => false ,
298- }
300+ matches ! (
301+ path. get_ident( ) . map( |ident| ident. to_string( ) ) . as_deref( ) ,
302+ Some ( "u8" )
303+ | Some ( "u16" )
304+ | Some ( "u32" )
305+ | Some ( "u64" )
306+ | Some ( "u128" )
307+ | Some ( "i8" )
308+ | Some ( "i16" )
309+ | Some ( "i32" )
310+ | Some ( "i64" )
311+ | Some ( "i128" )
312+ | Some ( "bool" )
313+ | Some ( "String" )
314+ )
299315 } else {
300316 false
301317 }
0 commit comments