How it works...
While design patterns, if-else constructs, and API design, in general, facilitate reusing code, it becomes tricky when it's time to hardcode tokens (for example, certain names) to remain loosely coupled. Rust's macros can help with that. As an example, we generate functions and tests for those functions in an effort to avoid copying and pasting test code around files.
In step 3, we declare a macro that wraps around comparing the lengths of two sequences and provides a better error message. Step 4 uses this macro right away and creates a function with the name provided, but only if the lengths of the multiple input Vec instances match.
In step 5, we call the macros and provide them with the required input: a name (for the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access