circumfix

Macro circumfix 

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

suffix! and prefix! in a single operation.

circumfix! {
	(<<)
	(>>)
	[{foo}, {bar}, {baz}]
}

// Expands to:
// << foo >>
// << bar >>
// << baz >>

With mapping macro:

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

circumfix! {
	{wrap_in_parens}
	(<<)
	(>>)
	[{foo}, {bar}, {baz}]
}

// Expands to:
// ( << foo >> )
// ( << bar >> )
// ( << baz >> )