Closed
Description
Since #10649, macro_rules!
macros can return multiple items. But there is no easy way to do so from a syntax extension: the result value must implement MacResult
and the appropriate implementation appear to be MacItem
, but it can only hold one item.
In servo/servo#3142, I worked around this with a new MacItems
(plural) type:
struct MacItems {
items: SmallVector<Gc<ast::Item>>
}
impl MacItems {
fn new<I: Iterator<Gc<ast::Item>>>(items: I) -> Box<MacResult> {
box MacItems { items: items.collect() } as Box<MacResult>
}
impl MacResult for MacItems {
fn make_items(&self) -> Option<SmallVector<Gc<ast::Item>>> {
// FIXME: Implement Clone on SmallVector and use it instead of .iter().collect()
Some(self.items.iter().collect())
}
}
Perhaps this could be added to libsyntax or merged with MacItem
.