21
Macros
Never limit yourself because of others’ limited imagination.
— Mae Jemison
The use of macros allows you to reimagine Rust within the context of your own aspirations. Rust’s support of macros is a powerful feature that provides almost unlimited capabilities. You can provide new features, implement default behavior, or simply avoid redundancy.
The println!
macro is probably the most well-known macro in the Rust universe. It provides the capability of a variadic function. This is because Rust does not support variadic functions. Therefore, the println!
macro provides a feature not available in the standard language. A close second in popularity is the derive
attribute. The derive
attribute for the Clone and Copy traits, for example, is ...
Get Programming with Rust now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.