Scrapmetal — Scrap Your Rust Boilerplate

TLDR: I translated some of the code and ideas from Scrap Your Boilerplate: A Practical Design Pattern for Generic Programming by Lämmel and Peyton Jones to Rust and it's available as the scrapmetal crate.


Interesting read.

The article reminds me of a problem that had to be solved in the gltf crate, namely checking the bounds of all indices in a complex data structure. It's seemed like a simple problem to solve, but making sure no index was left unchecked was difficult.

The solution used a Validate trait plus a procedural macro that generated the code to propagate down the data structures. All that was necessary was to wrap the indices in an Index type, implement Validate on Index and voilà, the compiler would guarantee that each and every index would be checked.