diff options
Diffstat (limited to 'engine-macros/src/reflection/struct_impl.rs')
| -rw-r--r-- | engine-macros/src/reflection/struct_impl.rs | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/engine-macros/src/reflection/struct_impl.rs b/engine-macros/src/reflection/struct_impl.rs index 2a271e0..b1adea5 100644 --- a/engine-macros/src/reflection/struct_impl.rs +++ b/engine-macros/src/reflection/struct_impl.rs @@ -1,7 +1,7 @@ use quote::quote; use crate::reflection::field::{generate as generate_field, ReflectionFieldGenOptions}; -use crate::util::find_engine_crate_path; +use crate::util::{find_engine_crate_path, syn_path, SynPathExt}; pub fn generate(input: syn::ItemStruct) -> proc_macro2::TokenStream { @@ -9,7 +9,22 @@ pub fn generate(input: syn::ItemStruct) -> proc_macro2::TokenStream let input_ident = input.ident; - let (impl_generics, type_generics, where_clause) = input.generics.split_for_impl(); + let type_reflection_optional = input.generics.params.is_empty(); + + let mut generics = input.generics; + + for type_param in generics.type_params_mut() { + type_param + .bounds + .push(syn::TypeParamBound::Trait(syn::TraitBound { + paren_token: None, + modifier: syn::TraitBoundModifier::None, + lifetimes: None, + path: engine_crate_path.join(syn_path!(reflection::Reflection)), + })); + } + + let (impl_generics, type_generics, where_clause) = generics.split_for_impl(); let fields = input .fields @@ -29,7 +44,7 @@ pub fn generate(input: syn::ItemStruct) -> proc_macro2::TokenStream quote! { std::mem::offset_of!(Self, #field_index) } } }, - type_reflection_optional: input.generics.params.is_empty(), + type_reflection_optional, }, ) }); |
