| @@ -66,8 +66,11 @@ pub fn msg_include_all(input: TokenStream) -> TokenStream { | |||
| let message_structs = get_packages(&paths) | |||
| .unwrap() | |||
| .iter() | |||
| .map(|v| v.struct_token_stream(config.create_cxx_bridge)) | |||
| .map(|v| v.message_structs(config.create_cxx_bridge)) | |||
| .collect::<Vec<_>>(); | |||
| let message_struct_defs = message_structs.iter().map(|(s, _)| s); | |||
| let message_struct_impls = message_structs.iter().map(|(_, i)| i); | |||
| let aliases = get_packages(&paths) | |||
| .unwrap() | |||
| .iter() | |||
| @@ -100,16 +103,18 @@ pub fn msg_include_all(input: TokenStream) -> TokenStream { | |||
| chars: Vec<u16>, | |||
| } | |||
| impl crate::_core::InternalDefault for U16String { | |||
| fn _default() -> Self { | |||
| Default::default() | |||
| } | |||
| } | |||
| #(#message_struct_defs)* | |||
| } | |||
| #(#message_structs)* | |||
| impl crate::_core::InternalDefault for ffi::U16String { | |||
| fn _default() -> Self { | |||
| Default::default() | |||
| } | |||
| } | |||
| #(#message_struct_impls)* | |||
| #(#aliases)* | |||
| @@ -123,7 +123,11 @@ pub struct Message { | |||
| } | |||
| impl Message { | |||
| pub fn struct_token_stream(&self, package_name: &Ident, gen_cxx_bridge: bool) -> impl ToTokens { | |||
| pub fn struct_token_stream( | |||
| &self, | |||
| package_name: &Ident, | |||
| gen_cxx_bridge: bool, | |||
| ) -> (impl ToTokens, impl ToTokens) { | |||
| let cxx_name = format_ident!("{}", self.name); | |||
| let struct_raw_name = format_ident!("{package_name}__{}", self.name); | |||
| @@ -141,17 +145,18 @@ impl Message { | |||
| }; | |||
| if self.members.is_empty() { | |||
| quote! {} | |||
| (quote! {}, quote! {}) | |||
| } else { | |||
| quote! { | |||
| let def = quote! { | |||
| #[allow(non_camel_case_types)] | |||
| #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] | |||
| #attributes | |||
| pub struct #struct_raw_name { | |||
| #(#rust_type_def_inner)* | |||
| } | |||
| impl crate::_core::InternalDefault for #struct_raw_name { | |||
| }; | |||
| let impls = quote! { | |||
| impl crate::_core::InternalDefault for ffi::#struct_raw_name { | |||
| fn _default() -> Self { | |||
| Self { | |||
| #(#rust_type_default_inner)* | |||
| @@ -159,13 +164,15 @@ impl Message { | |||
| } | |||
| } | |||
| impl std::default::Default for #struct_raw_name { | |||
| impl std::default::Default for ffi::#struct_raw_name { | |||
| #[inline] | |||
| fn default() -> Self { | |||
| crate::_core::InternalDefault::_default() | |||
| } | |||
| } | |||
| } | |||
| }; | |||
| (def, impls) | |||
| } | |||
| } | |||
| @@ -26,19 +26,25 @@ impl Package { | |||
| self.messages.is_empty() && self.services.is_empty() && self.actions.is_empty() | |||
| } | |||
| fn message_structs(&self, package_name: Ident, gen_cxx_bridge: bool) -> impl ToTokens { | |||
| pub fn message_structs(&self, gen_cxx_bridge: bool) -> (impl ToTokens, impl ToTokens) { | |||
| let package_name = Ident::new(&self.name, Span::call_site()); | |||
| if self.messages.is_empty() { | |||
| quote! { | |||
| // empty msg | |||
| } | |||
| // empty msg | |||
| (quote! {}, quote! {}) | |||
| } else { | |||
| let items = self | |||
| .messages | |||
| .iter() | |||
| .map(|v| v.struct_token_stream(&package_name, gen_cxx_bridge)); | |||
| quote! { | |||
| #(#items)* | |||
| } | |||
| let defs = items.clone().map(|(def, _)| def); | |||
| let impls = items.clone().map(|(_, im)| im); | |||
| let def_tokens = quote! { | |||
| #(#defs)* | |||
| }; | |||
| let impl_tokens = quote! { | |||
| #(#impls)* | |||
| }; | |||
| (def_tokens, impl_tokens) | |||
| } | |||
| } | |||
| @@ -108,15 +114,6 @@ impl Package { | |||
| } | |||
| } | |||
| pub fn struct_token_stream(&self, gen_cxx_bridge: bool) -> impl ToTokens { | |||
| let package_name = Ident::new(&self.name, Span::call_site()); | |||
| let message_structs = self.message_structs(package_name, gen_cxx_bridge); | |||
| quote! { | |||
| #message_structs | |||
| } | |||
| } | |||
| pub fn aliases_token_stream(&self) -> impl ToTokens { | |||
| let package_name = Ident::new(&self.name, Span::call_site()); | |||
| let aliases = self.message_aliases(&package_name); | |||