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