5
5
6
6
use proc_macro2:: { Punct , Spacing , Span , TokenStream , TokenTree } ;
7
7
use quote:: { quote, TokenStreamExt , ToTokens } ;
8
- use syn:: { Data , DeriveInput , Expr , Fields , FieldsNamed , FieldsUnnamed , Generics , Ident , Index , Lit , Member , Path , TypeTraitObject , Type , TypePath , ImplItemMethod } ;
8
+ use syn:: { Data , DeriveInput , Expr , Fields , FieldsNamed , FieldsUnnamed , Generics , Ident , Index , Lit , Member , TypeTraitObject , Type , TypePath , ImplItemMethod } ;
9
9
use syn:: { parse_quote, braced, bracketed, parenthesized} ;
10
10
use syn:: parse:: { Error , Parse , ParseStream , Result } ;
11
11
use syn:: token:: { Brace , Colon , Comma , Eq , FatArrow , Impl , Paren , Pound , RArrow , Semi , Struct , Underscore , Where } ;
@@ -355,6 +355,11 @@ impl Parse for HandlerArgs {
355
355
}
356
356
}
357
357
358
+ pub enum Class {
359
+ Container ( Ident ) ,
360
+ Frame ,
361
+ }
362
+
358
363
pub enum ChildType {
359
364
Fixed ( Type ) , // fixed type
360
365
// Generic, optionally with specified handler response type,
@@ -370,10 +375,8 @@ pub struct WidgetField {
370
375
}
371
376
372
377
pub struct MakeWidget {
373
- // layout direction
374
- pub layout : Ident ,
375
378
// widget class
376
- pub class : Option < Path > ,
379
+ pub class : Class ,
377
380
// response type
378
381
pub response : Type ,
379
382
// child widgets and data fields
@@ -384,23 +387,23 @@ pub struct MakeWidget {
384
387
385
388
impl Parse for MakeWidget {
386
389
fn parse ( input : ParseStream ) -> Result < Self > {
387
- let layout: Ident = input. parse ( ) ?;
388
- let _: FatArrow = input. parse ( ) ?;
390
+ let class_name: Ident = input. parse ( ) ?;
391
+ let class = if class_name == "container" {
392
+ let content;
393
+ let _ = parenthesized ! ( content in input) ;
394
+ let layout: Ident = content. parse ( ) ?;
395
+ Class :: Container ( layout)
396
+ } else if class_name == "frame" {
397
+ Class :: Frame
398
+ } else {
399
+ return Err ( Error :: new ( class_name. span ( ) ,
400
+ "make_widget only supports the following classes: container, frame" ) ) ;
401
+ } ;
389
402
403
+ let _: FatArrow = input. parse ( ) ?;
390
404
let response: Type = input. parse ( ) ?;
391
405
let _: Semi = input. parse ( ) ?;
392
406
393
- // TODO: revise attributes?
394
- let class = if input. peek ( kw:: class) {
395
- let _: kw:: class = input. parse ( ) ?;
396
- let _: Eq = input. parse ( ) ?;
397
- let class: Path = input. parse ( ) ?;
398
- let _: Semi = input. parse ( ) ?;
399
- Some ( class)
400
- } else {
401
- None
402
- } ;
403
-
404
407
let _: Struct = input. parse ( ) ?;
405
408
let content;
406
409
let _ = braced ! ( content in input) ;
@@ -436,7 +439,7 @@ impl Parse for MakeWidget {
436
439
impls. push ( ( target, methods) ) ;
437
440
}
438
441
439
- Ok ( MakeWidget { layout , class, response, fields, impls } )
442
+ Ok ( MakeWidget { class, response, fields, impls } )
440
443
}
441
444
}
442
445
0 commit comments