difftreelog
feat support generics for derive(Typed)
in: master
1 file changed
crates/jrsonnet-macros/src/lib.rsdiffbeforeafterboth591 .map(TypedField::parse)591 .map(TypedField::parse)592 .collect::<Result<Vec<_>>>()?;592 .collect::<Result<Vec<_>>>()?;593594 let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl( );593595594 let typed = {596 let typed = {595 let fields = fields597 let fields = fields596 .iter()598 .iter()597 .flat_map(TypedField::expand_field)599 .flat_map(TypedField::expand_field)598 .collect::<Vec<_>>();600 .collect::<Vec<_>>();599 let len = fields.len();600 quote! {601 quote! {601 const ITEMS: [(&'static str, &'static ComplexValType); #len] = [602 #(#fields,)*603 ];604 impl Typed for #ident {602 impl #impl_generics Typed for #ident #ty_generics #where_clause {605 const TYPE: &'static ComplexValType = &ComplexValType::ObjectRef(&ITEMS);603 const TYPE: &'static ComplexValType = &ComplexValType::ObjectRef(&[604 #(#fields,)*605 ]);606606607 fn from_untyped(value: Val) -> Result<Self> {607 fn from_untyped(value: Val) -> JrResult<Self> {608 let obj = value.as_obj().expect("shape is correct");608 let obj = value.as_obj().expect("shape is correct");609 Self::parse(&obj)609 Self::parse(&obj)610 }610 }611611612 fn into_untyped(value: Self) -> Result<Val> {612 fn into_untyped(value: Self) -> JrResult<Val> {613 let mut out = ObjValueBuilder::new();613 let mut out = ObjValueBuilder::new();614 value.serialize(&mut out)?;614 value.serialize(&mut out)?;615 Ok(Val::Obj(out.build()))615 Ok(Val::Obj(out.build()))636636637 #typed637 #typed638638639 impl TypedObj for #ident {639 impl #impl_generics TypedObj for #ident #ty_generics #where_clause {640 fn serialize(self, out: &mut ObjValueBuilder) -> JrResult<()> {640 fn serialize(self, out: &mut ObjValueBuilder) -> JrResult<()> {641 #(#fields_serialize)*641 #(#fields_serialize)*642642