@@ -164,6 +164,47 @@ pub trait MacResult {
164164 }
165165}
166166
167+ /// Single type implementing MacResult with Option fields for all the types
168+ /// MacResult can return , and a Default impl that fills in None .
169+ pub struct MacGeneral {
170+ expr: Option < P < ast:: Expr > > ,
171+ pat: Option < P < ast:: Pat > > ,
172+ items: Option < SmallVector < P < ast:: Item > > > ,
173+ methods: Option < SmallVector < P < ast:: Method > > > ,
174+ def : Option < MacroDef >
175+ }
176+ impl MacGeneral {
177+ pub fn new( expr: Option < P < ast:: Expr > > ,
178+ pat: Option < P < ast:: Pat > > ,
179+ items: Option < SmallVector < P < ast:: Items > > > ,
180+ methods: Option < SmallVector < P < ast:: Method > > > ,
181+ def : Option < MacroDef > )
182+ -> Box < MacResult +' static > {
183+ box MacGeneral { expr : expr, pat : pat, items : items,
184+ methods : methods, def : def } as Box < MacResult +' static >
185+ }
186+ pub fn Default ( ) -> Box < MacResult +' static > {
187+ box MacGeneral { expr : None , pat : None , items : None
188+ methods: None , def : None } as Box < MacResult +' static >
189+ }
190+ }
191+ impl MacResult for MacGeneral {
192+ fn make_expr( self : Box < MacGeneral > ) -> Option < P < ast:: Expr > > {
193+ self . expr
194+ }
195+ fn make_pat( self : Box < MacGeneral > ) -> Option < P < ast:: Pat > > {
196+ self . pat
197+ }
198+ fn make_items( self : Box < MacGeneral > ) -> Option < SmallVector < P < ast:: Item > > > {
199+ self . items
200+ }
201+ fn make_methods( self : Box < Self > ) -> Option < SmallVector < P < ast:: Method > > > {
202+ self . methods
203+ }
204+ fn make_def( & mut self ) -> Option < MacroDef > {
205+ self . def
206+ }
207+ }
167208/// A convenience type for macros that return a single expression.
168209pub struct MacExpr {
169210 e : P < ast:: Expr >
0 commit comments