diff options
Diffstat (limited to 'engine-macros/src/reflection/struct_impl.rs')
| -rw-r--r-- | engine-macros/src/reflection/struct_impl.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/engine-macros/src/reflection/struct_impl.rs b/engine-macros/src/reflection/struct_impl.rs new file mode 100644 index 0000000..57e3e21 --- /dev/null +++ b/engine-macros/src/reflection/struct_impl.rs @@ -0,0 +1,46 @@ +use quote::quote; + +use crate::reflection::field::{generate as generate_field, ReflectionFieldGenOptions}; +use crate::util::find_engine_crate_path; + +pub fn generate(input: syn::ItemStruct) -> proc_macro2::TokenStream +{ + let engine_crate_path = find_engine_crate_path().unwrap(); + + let input_ident = input.ident; + + let (impl_generics, type_generics, where_clause) = input.generics.split_for_impl(); + + let fields = input + .fields + .into_iter() + .enumerate() + .map(|(field_index, field)| { + generate_field( + &field, + field_index, + &engine_crate_path, + ReflectionFieldGenOptions { + field_vis_override: None, + include_byte_offset: true, + }, + ) + }); + + quote! { + unsafe impl #impl_generics #engine_crate_path::reflection::Reflection for + #input_ident #type_generics #where_clause + { + const TYPE_REFLECTION: &#engine_crate_path::reflection::Type = + &const { + #engine_crate_path::reflection::Type::Struct( + #engine_crate_path::reflection::Struct { + fields: &[ + #(#fields),* + ] + } + ) + }; + } + } +} |
