diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 5401da8cd053b..0361a71c2e9a6 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -164,6 +164,47 @@ pub trait MacResult { } } +/// Single type implementing MacResult with Option fields for all the types +/// MacResult can return, and a Default impl that fills in None. +pub struct MacGeneral { + expr: Option>, + pat: Option>, + items: Option>>, + methods: Option>>, + def: Option +} +impl MacGeneral { + pub fn new(expr: Option>, + pat: Option>, + items: Option>>, + methods: Option>>, + def: Option) + -> Box { + box MacGeneral { expr: expr, pat: pat, items: items, + methods: methods, def: def } as Box + } + pub fn Default() -> Box { + box MacGeneral { expr: None, pat: None, items: None + methods: None, def: None} as Box + } +} +impl MacResult for MacGeneral { + fn make_expr(self: Box) -> Option> { + self.expr + } + fn make_pat(self: Box) -> Option> { + self.pat + } + fn make_items(self: Box) -> Option>> { + self.items + } + fn make_methods(self: Box) -> Option>> { + self.methods + } + fn make_def(&mut self) -> Option { + self.def + } +} /// A convenience type for macros that return a single expression. pub struct MacExpr { e: P