@@ -3,7 +3,7 @@ use std::collections::HashMap;
33use convert_case:: { Case , Casing } ;
44use proc_macro2:: { Literal , TokenStream } ;
55use quote:: { ToTokens , TokenStreamExt , format_ident, quote} ;
6- use syn:: { DataStruct , DeriveInput , Fields , FieldsNamed , FieldsUnnamed , Ident , Result } ;
6+ use syn:: { DataStruct , DeriveInput , Fields , FieldsNamed , FieldsUnnamed , Generics , Ident , Result } ;
77
88use crate :: validate:: field:: ValidateField ;
99
@@ -38,6 +38,7 @@ impl ToTokens for ValidateStruct {
3838pub struct ValidateNamedStruct {
3939 ident : Ident ,
4040 error_ident : Ident ,
41+ generics : Generics ,
4142 fields : HashMap < Ident , ValidateField > ,
4243}
4344
@@ -46,6 +47,7 @@ impl ValidateNamedStruct {
4647 let mut result = Self {
4748 ident : input. ident . clone ( ) ,
4849 error_ident : format_ident ! ( "{}ValidationError" , input. ident) ,
50+ generics : input. generics . clone ( ) ,
4951 fields : HashMap :: default ( ) ,
5052 } ;
5153
@@ -70,6 +72,8 @@ impl ToTokens for ValidateNamedStruct {
7072 fn to_tokens ( & self , tokens : & mut TokenStream ) {
7173 let ident = & self . ident ;
7274 let error_ident = & self . error_ident ;
75+ let ( impl_generics, type_generics, where_clause) = & self . generics . split_for_impl ( ) ;
76+
7377 let mut error_field_idents = vec ! [ ] ;
7478 let mut error_field_types = vec ! [ ] ;
7579 let mut error_field_enums = vec ! [ ] ;
@@ -127,7 +131,7 @@ impl ToTokens for ValidateNamedStruct {
127131 #( #error_field_enums) *
128132
129133 #[ automatically_derived]
130- impl Validate for #ident {
134+ impl #impl_generics Validate for #ident #type_generics #where_clause {
131135 type Error = #error_ident;
132136
133137 fn validate_sync( & self ) -> Result <( ) , ValidationErrors <Self :: Error >> {
@@ -163,6 +167,7 @@ impl ToTokens for ValidateNamedStruct {
163167pub struct ValidateUnnamedStruct {
164168 ident : Ident ,
165169 error_ident : Ident ,
170+ generics : Generics ,
166171 fields : Vec < ValidateField > ,
167172}
168173
@@ -171,6 +176,7 @@ impl ValidateUnnamedStruct {
171176 let mut result = Self {
172177 ident : input. ident . clone ( ) ,
173178 error_ident : format_ident ! ( "{}ValidationError" , input. ident) ,
179+ generics : input. generics . clone ( ) ,
174180 fields : Vec :: default ( ) ,
175181 } ;
176182
@@ -195,6 +201,8 @@ impl ToTokens for ValidateUnnamedStruct {
195201 fn to_tokens ( & self , tokens : & mut TokenStream ) {
196202 let ident = & self . ident ;
197203 let error_ident = & self . error_ident ;
204+ let ( impl_generics, type_generics, where_clause) = & self . generics . split_for_impl ( ) ;
205+
198206 let mut error_field_idents = vec ! [ ] ;
199207 let mut error_field_types = vec ! [ ] ;
200208 let mut error_field_enums = vec ! [ ] ;
@@ -251,7 +259,7 @@ impl ToTokens for ValidateUnnamedStruct {
251259 #( #error_field_enums) *
252260
253261 #[ automatically_derived]
254- impl Validate for #ident {
262+ impl #impl_generics Validate for #ident #type_generics #where_clause {
255263 type Error = #error_ident;
256264
257265 fn validate_sync( & self ) -> Result <( ) , ValidationErrors <Self :: Error >> {
@@ -286,25 +294,28 @@ impl ToTokens for ValidateUnnamedStruct {
286294
287295pub struct ValidateUnitStruct {
288296 ident : Ident ,
297+ generics : Generics ,
289298}
290299
291300impl ValidateUnitStruct {
292301 fn parse ( input : & DeriveInput ) -> Result < Self > {
293302 Ok ( Self {
294303 ident : input. ident . clone ( ) ,
304+ generics : input. generics . clone ( ) ,
295305 } )
296306 }
297307}
298308
299309impl ToTokens for ValidateUnitStruct {
300310 fn to_tokens ( & self , tokens : & mut TokenStream ) {
301311 let ident = & self . ident ;
312+ let ( impl_generics, type_generics, where_clause) = & self . generics . split_for_impl ( ) ;
302313
303314 tokens. append_all ( quote ! {
304315 use fortifier:: ValidationErrors ;
305316
306317 #[ automatically_derived]
307- impl Validate for #ident {
318+ impl #impl_generics Validate for #ident #type_generics #where_clause {
308319 type Error = :: std:: convert:: Infallible ;
309320
310321 fn validate_sync( & self ) -> Result <( ) , ValidationErrors <Self :: Error >> {
0 commit comments