--- a/crates/jrsonnet-macros/src/lib.rs +++ b/crates/jrsonnet-macros/src/lib.rs @@ -591,25 +591,25 @@ .map(TypedField::parse) .collect::>>()?; + let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl( ); + let typed = { let fields = fields .iter() .flat_map(TypedField::expand_field) .collect::>(); - let len = fields.len(); quote! { - const ITEMS: [(&'static str, &'static ComplexValType); #len] = [ - #(#fields,)* - ]; - impl Typed for #ident { - const TYPE: &'static ComplexValType = &ComplexValType::ObjectRef(&ITEMS); + impl #impl_generics Typed for #ident #ty_generics #where_clause { + const TYPE: &'static ComplexValType = &ComplexValType::ObjectRef(&[ + #(#fields,)* + ]); - fn from_untyped(value: Val) -> Result { + fn from_untyped(value: Val) -> JrResult { let obj = value.as_obj().expect("shape is correct"); Self::parse(&obj) } - fn into_untyped(value: Self) -> Result { + fn into_untyped(value: Self) -> JrResult { let mut out = ObjValueBuilder::new(); value.serialize(&mut out)?; Ok(Val::Obj(out.build())) @@ -636,7 +636,7 @@ #typed - impl TypedObj for #ident { + impl #impl_generics TypedObj for #ident #ty_generics #where_clause { fn serialize(self, out: &mut ObjValueBuilder) -> JrResult<()> { #(#fields_serialize)*