A space after colons in macros

#1

I note that while style guide says “Use a space after colons”, almost no existing codes does so in macros. For example,

macro_rules! try(
    ($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) })
)

That is, $e:expr, not $e: expr.

What do you prefer?

0 Likes

#2

Former. No reason, other than everyone else follows that style too.

0 Likes

#3

I try to use $e: expr because the expr is essentially a type for the $e variable.

0 Likes

#4

I prefer $e:expr, it makes it clear that expr is part of the nonterminal pattern token.

0 Likes

#5

I personally prefer $e: expr, it seems more consistent to me. I actually tend to be confused/surprised for a second, whenever I come across the space-less variant.

0 Likes

#6

Oh, everything makes sense now. I couldn’t even parse the syntax for macro_rules! because it just looked like magic macro things.

0 Likes

closed #7

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

0 Likes