@@ -85,7 +85,7 @@ enum PropAttr {
85
85
Get ( Option < syn:: Expr > ) ,
86
86
Set ( Option < syn:: Expr > ) ,
87
87
88
- // ident [ = expr]
88
+ // ident = expr
89
89
OverrideClass ( syn:: Type ) ,
90
90
OverrideInterface ( syn:: Type ) ,
91
91
@@ -177,33 +177,19 @@ struct ReceivedAttrs {
177
177
builder_fields : HashMap < syn:: Ident , Option < syn:: Expr > > ,
178
178
}
179
179
180
- impl ReceivedAttrs {
181
- fn new (
182
- attrs_span : & proc_macro2:: Span ,
183
- attrs : impl IntoIterator < Item = PropAttr > ,
184
- ) -> syn:: Result < Self > {
180
+ impl Parse for ReceivedAttrs {
181
+ fn parse ( input : syn:: parse:: ParseStream ) -> syn:: Result < Self > {
182
+ let attrs = syn:: punctuated:: Punctuated :: < PropAttr , Token ! [ , ] > :: parse_terminated ( input) ?;
185
183
let this = attrs. into_iter ( ) . fold ( Self :: default ( ) , |mut this, attr| {
186
184
this. set_from_attr ( attr) ;
187
185
this
188
186
} ) ;
189
187
190
- if this. get . is_none ( ) && this. set . is_none ( ) {
191
- return Err ( syn:: Error :: new (
192
- * attrs_span,
193
- "No `get` or `set` specified: at least one is required." . to_string ( ) ,
194
- ) ) ;
195
- }
196
-
197
- if this. override_class . is_some ( ) && this. override_interface . is_some ( ) {
198
- return Err ( syn:: Error :: new (
199
- * attrs_span,
200
- "Both `override_class` and `override_interface` specified." . to_string ( ) ,
201
- ) ) ;
202
- }
203
-
204
188
Ok ( this)
205
189
}
190
+ }
206
191
192
+ impl ReceivedAttrs {
207
193
fn set_from_attr ( & mut self , attr : PropAttr ) {
208
194
match attr {
209
195
PropAttr :: Get ( some_fn) => self . get = Some ( some_fn. into ( ) ) ,
@@ -258,6 +244,21 @@ impl PropDesc {
258
244
builder_fields,
259
245
} = attrs;
260
246
247
+ if get. is_none ( ) && set. is_none ( ) {
248
+ return Err ( syn:: Error :: new (
249
+ attrs_span,
250
+ "No `get` or `set` specified: at least one is required." . to_string ( ) ,
251
+ ) ) ;
252
+ }
253
+
254
+ if override_class. is_some ( ) && override_interface. is_some ( ) {
255
+ return Err ( syn:: Error :: new (
256
+ attrs_span,
257
+ "Both `override_class` and `override_interface` specified." . to_string ( ) ,
258
+ ) ) ;
259
+ }
260
+
261
+
261
262
// Fill needed, but missing, attributes with calculated default values
262
263
let name = name. unwrap_or_else ( || {
263
264
syn:: LitStr :: new (
@@ -469,16 +470,13 @@ fn parse_fields(fields: syn::Fields) -> syn::Result<Vec<PropDesc>> {
469
470
attrs
470
471
. into_iter ( )
471
472
. filter ( |a| a. path . is_ident ( "property" ) )
472
- . map ( move |attrs| {
473
- let span = attrs. span ( ) ;
474
- let attrs = attrs. parse_args_with (
475
- syn:: punctuated:: Punctuated :: < PropAttr , Token ! [ , ] > :: parse_terminated,
476
- ) ?;
473
+ . map ( move |prop_attrs| {
474
+ let span = prop_attrs. span ( ) ;
477
475
PropDesc :: new (
478
476
span,
479
477
ident. as_ref ( ) . unwrap ( ) . clone ( ) ,
480
478
ty. clone ( ) ,
481
- ReceivedAttrs :: new ( & span , attrs ) ? ,
479
+ prop_attrs . parse_args ( ) ?
482
480
)
483
481
} )
484
482
} )
0 commit comments