How to Use Rust Procedural Macros to Replace Panic with syn’s Fold In this article, we show how you can write advanced macros to step through Rust code and modify it. Using the standard tooling available in the syn crate, we first show how to change the occurrence of a panic into an Err. Then we go a step beyond and use the Fold trait to recursively step through the entire function, automatically