0

It's just curiosity, I noted that macros have the same behavior independently the delimiter with we call the macro, for example println!(....) have same behavior of println!{....} or println![....].

Is this in fact so, or is it nuanced? and Exists any formal explanation for this?

al3x
  • 589
  • 1
  • 4
  • 16

1 Answers1

0

They're largely identical. You usually choose one that fits the scenario; if you're using a function-like macro (e.g. println!) you'd use parentheses, an array-like macro (e.g. vec!) you'd use square brackets, and use curly braces when it forms a logical block.

To my knowledge, the only difference between them is that curly braces ({}) are recognized as a block, so when you use them, you don't need to put a ; at the end to make it a valid statement, where you would need to do so if you used () or [].

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271