aboutsummaryrefslogtreecommitdiff
path: root/mingling_macros/src/derive/structural_data.rs
diff options
context:
space:
mode:
Diffstat (limited to 'mingling_macros/src/derive/structural_data.rs')
-rw-r--r--mingling_macros/src/derive/structural_data.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/mingling_macros/src/derive/structural_data.rs b/mingling_macros/src/derive/structural_data.rs
new file mode 100644
index 0000000..acb2f28
--- /dev/null
+++ b/mingling_macros/src/derive/structural_data.rs
@@ -0,0 +1,26 @@
+use proc_macro::TokenStream;
+use quote::quote;
+use syn::{DeriveInput, parse_macro_input};
+
+use crate::get_global_set;
+
+/// Derive macro for `StructuralData`.
+pub(crate) fn derive_structural_data(input: TokenStream) -> TokenStream {
+ let input = parse_macro_input!(input as DeriveInput);
+ let type_name = input.ident;
+
+ // Register in STRUCTURED_TYPES
+ let type_name_str = type_name.to_string();
+ get_global_set(&crate::STRUCTURED_TYPES)
+ .lock()
+ .unwrap()
+ .insert(type_name_str);
+
+ // Generate BOTH the sealed impl AND the StructuralData impl.
+ let expanded = quote! {
+ impl ::mingling::__private::StructuralDataSealed<crate::ThisProgram> for #type_name {}
+ impl ::mingling::__private::StructuralData<crate::ThisProgram> for #type_name {}
+ };
+
+ expanded.into()
+}