@@ -10,14 +10,14 @@ use crate::{
1010 validation:: Execution ,
1111} ;
1212
13- pub enum ValidateFields {
14- Named ( ValidateNamedFields ) ,
15- Unnamed ( ValidateUnnamedFields ) ,
13+ pub enum ValidateFields < ' a > {
14+ Named ( ValidateNamedFields < ' a > ) ,
15+ Unnamed ( ValidateUnnamedFields < ' a > ) ,
1616 Unit ( ValidateUnitFields ) ,
1717}
1818
19- impl ValidateFields {
20- pub fn parse ( visibility : & Visibility , ident : & Ident , fields : & Fields ) -> Result < Self > {
19+ impl < ' a > ValidateFields < ' a > {
20+ pub fn parse ( visibility : & ' a Visibility , ident : Ident , fields : & ' a Fields ) -> Result < Self > {
2121 Ok ( match fields {
2222 Fields :: Named ( fields) => {
2323 Self :: Named ( ValidateNamedFields :: parse ( visibility, ident, fields) ?)
@@ -55,19 +55,21 @@ impl ValidateFields {
5555 }
5656}
5757
58- pub struct ValidateNamedFields {
59- visibility : Visibility ,
58+ pub struct ValidateNamedFields < ' a > {
59+ visibility : & ' a Visibility ,
6060 ident : Ident ,
6161 error_ident : Ident ,
62- fields : Vec < ValidateField > ,
62+ fields : Vec < ValidateField < ' a > > ,
6363}
6464
65- impl ValidateNamedFields {
66- fn parse ( visibility : & Visibility , ident : & Ident , fields : & FieldsNamed ) -> Result < Self > {
65+ impl < ' a > ValidateNamedFields < ' a > {
66+ fn parse ( visibility : & ' a Visibility , ident : Ident , fields : & ' a FieldsNamed ) -> Result < Self > {
67+ let error_ident = format_ident ! ( "{}ValidationError" , ident) ;
68+
6769 let mut result = Self {
68- visibility : visibility . clone ( ) ,
69- ident : ident . clone ( ) ,
70- error_ident : format_ident ! ( "{}ValidationError" , ident ) ,
70+ visibility,
71+ ident,
72+ error_ident,
7173 fields : Vec :: with_capacity ( fields. named . len ( ) ) ,
7274 } ;
7375
@@ -78,7 +80,7 @@ impl ValidateNamedFields {
7880
7981 result. fields . push ( ValidateField :: parse (
8082 visibility,
81- ident,
83+ & result . ident ,
8284 LiteralOrIdent :: Ident ( field_ident. clone ( ) ) ,
8385 field,
8486 ) ?) ;
@@ -93,7 +95,7 @@ impl ValidateNamedFields {
9395
9496 fn error_type ( & self ) -> ( TokenStream , TokenStream ) {
9597 error_type (
96- & self . visibility ,
98+ self . visibility ,
9799 & self . ident ,
98100 & self . error_ident ,
99101 self . fields . iter ( ) ,
@@ -116,26 +118,28 @@ impl ValidateNamedFields {
116118 }
117119}
118120
119- pub struct ValidateUnnamedFields {
120- visibility : Visibility ,
121+ pub struct ValidateUnnamedFields < ' a > {
122+ visibility : & ' a Visibility ,
121123 ident : Ident ,
122124 error_ident : Ident ,
123- fields : Vec < ValidateField > ,
125+ fields : Vec < ValidateField < ' a > > ,
124126}
125127
126- impl ValidateUnnamedFields {
127- fn parse ( visibility : & Visibility , ident : & Ident , fields : & FieldsUnnamed ) -> Result < Self > {
128+ impl < ' a > ValidateUnnamedFields < ' a > {
129+ fn parse ( visibility : & ' a Visibility , ident : Ident , fields : & ' a FieldsUnnamed ) -> Result < Self > {
130+ let error_ident = format_ident ! ( "{}ValidationError" , ident) ;
131+
128132 let mut result = Self {
129- visibility : visibility . clone ( ) ,
130- ident : ident . clone ( ) ,
131- error_ident : format_ident ! ( "{}ValidationError" , ident ) ,
133+ visibility,
134+ ident,
135+ error_ident,
132136 fields : Vec :: with_capacity ( fields. unnamed . len ( ) ) ,
133137 } ;
134138
135139 for ( index, field) in fields. unnamed . iter ( ) . enumerate ( ) {
136140 result. fields . push ( ValidateField :: parse (
137141 visibility,
138- ident,
142+ & result . ident ,
139143 LiteralOrIdent :: Literal ( Literal :: usize_unsuffixed ( index) ) ,
140144 field,
141145 ) ?) ;
@@ -150,7 +154,7 @@ impl ValidateUnnamedFields {
150154
151155 fn error_type ( & self ) -> ( TokenStream , TokenStream ) {
152156 error_type (
153- & self . visibility ,
157+ self . visibility ,
154158 & self . ident ,
155159 & self . error_ident ,
156160 self . fields . iter ( ) ,
@@ -195,7 +199,7 @@ fn error_type<'a>(
195199 visibility : & Visibility ,
196200 ident : & Ident ,
197201 error_ident : & Ident ,
198- fields : impl Iterator < Item = & ' a ValidateField > ,
202+ fields : impl Iterator < Item = & ' a ValidateField < ' a > > ,
199203) -> ( TokenStream , TokenStream ) {
200204 let attributes = enum_attributes ( ) ;
201205
@@ -207,7 +211,7 @@ fn error_type<'a>(
207211 let field_error_ident = field. error_ident ( ) ;
208212 let ( field_error_type, field_error_enum) = field. error_type ( ident) ;
209213
210- error_field_idents. push ( field_error_ident. clone ( ) ) ;
214+ error_field_idents. push ( field_error_ident) ;
211215 error_field_types. push ( field_error_type) ;
212216 if let Some ( error_enum) = field_error_enum {
213217 error_field_enums. push ( error_enum) ;
@@ -244,7 +248,7 @@ fn validations<'a>(
244248 field_prefix : ValidateFieldPrefix ,
245249 error_ident : & Ident ,
246250 error_wrapper : & impl Fn ( TokenStream ) -> TokenStream ,
247- fields : impl Iterator < Item = & ' a ValidateField > ,
251+ fields : impl Iterator < Item = & ' a ValidateField < ' a > > ,
248252) -> TokenStream {
249253 let error_ident = & error_ident;
250254
0 commit comments