In this section of documentation about procedural macros, the docs mention that there are mainly three types of macros, those are:
Function-like e.g. custom!()
Derive e.g. #[derive(Custom)]
Attribute e.g. #[custom]
I can understand attribute and procedural macros, but, at the same time, I wonder why function-like macros exist. Can't we have the same thing with declarative macros using macro_rules!?
So my question is:
What is the purpose of function-like macros?
Are there any function-like macros defined in the standard library? I think cfg!() is one of them.
No. All of the identifiers that macro deals with are spelled out literally in the code, and it compiles. This doesn't create any new identifiers. It declares a new type, but that's uninteresting from the PoV of macros (they have nothing to do with type checking and don't care about types).
Macros are purely syntactic abstractions. When I mean a new identifier, I mean an identifier and nothing more (in particular, I don't mean any program construct such as a type or variable that identifiers may refer to).