I recently tried to write a pipe macro that looked something like this:
macro_rules! pipe {
($it:expr,) => { $it };
($it:expr) => { $it };
($it:expr, $f:path($args:tt) $rest:tt) => {
pipe!($f($it, $args), $rest)
};
($it:expr, $m:path!($args:tt) $rest:tt) => {
let it = $it;
pipe!($m!:(it, $args), $rest)
};
}
which would allow you to write something like:
pipe!(item, foo(1,2) bar!("hi") a::b::baz())
that would expand to
a::b::baz(bar!(foo(item, 1, 2), "hi"))
but to my chagrin I discovered that neither “(” nor “!” are allowed to follow a path. I either have to use ident
instead, which would require the user to use
any functions (and macros in 2018 edition), and could possibly not work at all for some situations involving generics, or add one of the legal tokens between the path and the argument list, which isn’t very natural from the user’s point of view.
ex:
pipe!(item, foo|(1,2) bar|!("hi") a::b::baz|())
Is there a compelling reason not to allow ! or ( after a path? As far as I know, those aren’t legal characters in a path fragment.