Hi,
I'm trying to write a macro that will take in multiple objects, wrap them in RefCells and then later call methods on the wrapped objects using borrow_mut() on the RefCell. The wrapping RefCell would have the name ref_cell_$obj. It looks like this:
macro_rules! method (
(pub $name:ident<$a:ty,$i:ty,$o:ty>, $self_:ident, [ $( $obj:ident ),* ] , $submac:ident!( $($args:tt)* )) => (
pub fn $name( $self_: $a, i: $i ) -> nom::IResult<$i, $o> {
use std::cell::RefCell;
$(let concat_idents!(ref_cell_, $obj) = RefCell::new($obj)),*;
$submac!(i, $($args)*)
}
);
);
Presumably something in the $submac will eventually call a method on one of the $objs. But the error I'm getting with concat_idents is:
src/other.rs:30:13: 30:26 error: non-pattern macro in pattern position: concat_idents
src/other.rs:30 $(let concat_idents!(ref_cell_, $obj) = RefCell::new($obj)),*;
^~~~~~~~~~~~~
Does anybody know what this means and how to get around it? I tried to wrap concat_idents in another macro that made it return a tuple like (concat_idents!(ref_cell_, $obj),) which the Rust Programming Book section on Macros says should count as a pattern, but it still gives the same error.
I even looked at the Rust source code around the error message, and it seems to check to see if the macro expands into a pattern (which is why I tried to make it expand into a tuple), but I clearly I don't understand what it means by pattern.
Does anybody know how to do something like this (create new variables in a macro based on idents passed to the macro)?