3 ms·
In general as a rust programmer you'll end up consuming orders of magnitudes more macros than you'll ever write; from what I've seen macros are more commonly wr
by ashtonkem 7y ago
In general as a rust programmer you'll end up consuming orders of magnitudes more macros than you'll ever write; from what I've seen macros are more commonly written in libraries to make their use smoother, and my experience in other Macro heavy languages was similar (Clojure, SBCL).
But as others said, the point is boilerplate reduction. You can write a macro that'll automate that process away. A lot of examples are about automatically implementing certain behaviors for structs, such as equality, but you'll also see extensive macro use in ORM libraries that can generate a lot of runtime code off of a smaller table definition macro.
Anything with an explanation point is a macro invocation, by the way.
- justwalt 7y ago“Anything with an explanation point is a macro invocation, by the way.” Can you explain what this means, exactly?
- deleted 7y ago[deleted]
- steveklabnik 7y agoThis is a function invocation: foo(bar) This is a macro invocation: foo!(bar) It's done this way because macros can have much more complex things inside the ()s than functions can. This helps both humans and computers parse such things.
- lalaithion 7y agofoo(x, y, z) is a function. foo!(x, y, z) is a macro.
- deleted 7y ago[deleted]
- jack1243star 7y agoNot OP, I think they mean the exclamation mark (!)
- gnosek 7y agoExclamation mark. e.g. println!("hello, world"); or todo!(); are macro invocations.
- ccktlmazeltov 7y agoprintln!("something") that's a macro
- staticassertion 7y agoMacros: #[Foo] struct Bar {} baz!() cat!{} blah![]
- hinkley 7y agoexclamation point?
- ashtonkem 7y agoTIL that “Exclamation point” is region specific. Other people call it exclamation marks.