diff --git a/packages/proto-build/src/transform.rs b/packages/proto-build/src/transform.rs index 747a9fc9..9670c01a 100644 --- a/packages/proto-build/src/transform.rs +++ b/packages/proto-build/src/transform.rs @@ -100,7 +100,6 @@ fn transform_module( nested_mod: bool, ) -> Vec { let items = transform_items(items, src, ancestors, descriptor); - let items = prepend(items); append(items, src, descriptor, nested_mod) } @@ -131,7 +130,7 @@ fn transform_items( ancestors: &[String], descriptor: &FileDescriptorSet, ) -> Vec { - items + let items = items .into_iter() .map(|i| match i { Item::Struct(s) => Item::Struct({ @@ -155,7 +154,16 @@ fn transform_items( i => i, }) .map(|i: Item| transform_nested_mod(i, src, ancestors, descriptor)) - .collect::>() + .collect::>(); + + if items.clone().into_iter().any(|i| match i { + Item::Struct(_) => true, + _ => false, + }) { + prepend(items) + } else { + items + } } fn transform_nested_mod(