prefix

Macro prefix 

Source
macro_rules! prefix {
    (
		{$map:path}
		($($prefix:tt)*)
		[$(,)? {$($next:tt)*} $($rest:tt)*]
	) => { ... };
    (
		($($prefix:tt)*)
		[$(,)? {$($next:tt)*} $($rest:tt)*]
	) => { ... };
    (
		$({$map:path})?
		($($prefix:tt)*)
		[$(,)?]
	) => { ... };
}
Expand description

Prefixes tokens to groups of other tokens.

Optionally, a mapping macro can be provided to transform each resulting prefixed token group.

See also prefix_items! for a convenience wrapper around this macro for use with items.

prefix! {
	(foo)
	[{bar 1}, {baz 2}, {qux 3}]
}

// Expands to:
// foo bar 1
// foo baz 2
// foo qux 3

With mapping macro:

macro_rules! wrap_in_parens {
	($($tokens:tt)*) => {
		( $($tokens)* )
	};
}

prefix! {
	{wrap_in_parens}
	(foo)
	[{bar 1}, {baz 2}, {qux 3}]
}

// Expands to:
// ( foo bar 1 )
// ( foo baz 2 )
// ( foo qux 3 )