- Why did println! need two patterns?
Solution: The first pattern of println! matches a call where there is just the format string and no parameters. Without it, the following would match no rules:
- Why is println! a macro instead of just a function?
Solution: Having println! as a macro gives it the power of compile-time checking of its parameters. A print statement with a wrong number of arguments could never work, so it's nice that it fails at compile time. Furthermore, Rust does not have variable arguments (at least yet), so you would have to pass format arguments in a list or similar structure.
- Think about your second favorite compiled programming language. How does it do the same checks that println! ...