macro_rules! suffix {
(
{$map:path}
($($suffix:tt)*)
[$(,)? {$($next:tt)*} $($rest:tt)*]
) => { ... };
(
($($suffix:tt)*)
[$(,)? {$($next:tt)*} $($rest:tt)*]
) => { ... };
(
$({$map:path})?
($($suffix:tt)*)
[$(,)?]
) => { ... };
}Expand description
Suffixes tokens to groups of other tokens.
Optionally, a mapping macro can be provided to transform each resulting suffixed token group.
suffix! {
(foo)
[{bar 1}, {baz 2}, {qux 3}]
}
// Expands to:
// bar 1 foo
// baz 2 foo
// qux 3 fooWith mapping macro:
macro_rules! wrap_in_parens {
($($tokens:tt)*) => {
( $($tokens)* )
};
}
suffix! {
{wrap_in_parens}
(foo)
[{bar 1}, {baz 2}, {qux 3}]
}
// Expands to:
// ( bar 1 foo )
// ( baz 2 foo )
// ( qux 3 foo )