Writing complex macros in Rust: Reverse Polish Notation
This text discusses the implementation of a macro in Rust for evaluating Reverse Polish Notation (RPN) expressions at compile-time. The author explains how to use recursive macros, token types, and various branches to handle different cases such as operators, numbers, and stack manipulation. Additionally, error handling is covered with the help of built-in Rust macros like `compile_error!`, `concat!`, and `stringify!`. The final macro can evaluate any RPN expression and provides meaningful error messages for common mistakes.
Company
Cloudflare
Date published
Jan. 31, 2018
Author(s)
Ingvar Stepanyan
Word count
2765
Hacker News points
2
Language
English